Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Unity C# for beginner - unity part -
Search
mattak
June 28, 2016
Programming
0
280
Unity C# for beginner - unity part -
mattak
June 28, 2016
Tweet
Share
More Decks by mattak
See All by mattak
最近やった作業環境改善施策10個
mattak
0
250
UnixTime is Simple
mattak
0
170
おっさんが停滞しないために
mattak
32
18k
tech invest
mattak
1
300
Nodux - node base redux framework
mattak
0
1.4k
what_is_technical_investment
mattak
0
120
unitypackage distribution
mattak
0
770
Unity energy usage
mattak
0
860
Unidux 0.3.1
mattak
1
370
Other Decks in Programming
See All in Programming
return文におけるstd::moveについて
onihusube
1
1.1k
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
5
1.2k
42 best practices for Symfony, a decade later
tucksaun
1
180
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
410
MCP with Cloudflare Workers
yusukebe
2
220
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
770
Security_for_introducing_eBPF
kentatada
0
110
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
BBQ
matthewcrist
85
9.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Site-Speed That Sticks
csswizardry
2
190
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Optimising Largest Contentful Paint
csswizardry
33
3k
How STYLIGHT went responsive
nonsquared
95
5.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
A designer walks into a library…
pauljervisheath
204
24k
Transcript
Unity C# ⼊⾨ - Unity編 - 6OJUZษڧձ !NBUUBL
今⽇のメニュー!
C# Unity (BNF0CKFDU .POP#FIBWJPVS 3FTPVSDFT *OTUBOUJBUF
%FTUSPZ $PNQPOFOU *OQVU %FCVH 1SPpMF
1. GameObject
%্ۭؒʹஔ͞ΕΔͯ͢ͷ (BNF0CKFDUΫϥεͱͯ͠දݱ͞ΕΔ (BNF0CKFDU͕࣮ߦ࣌ͷؔͷΤϯτϦʔϙΠϯτʹͳΔɻ (BNF0CKFDUʹεΫϦϓτΛ͚ͭΔ͜ͱͰ ࡞ͨؔ͠ͷ࣮ߦ͕ՄೳʹͳΔɻ
.POP#FIBWJPVSʹHBNF0CKFDU͕ੜ͍͑ͯΔ public class SampleBehaviour : MonoBehaviour { void Start() {
this.gameObject; // ࢀরՄೳ } }
ͯ͢ͷ(BNF0CKFDUԼهΛ࣋ͭ this.gameObject.transform; // زԿมΛߦ͏ object this.gameObject.name; // Inspector্Ͱදࣔ͞ΕΔ໊લ this.gameObject.tag; //
Inspector্Ͱઃఆ͞ΕΔλά໊ this.gameObject.activeSelf; // ͜ͷGameObject͕༗ޮԽͲ͏͔ʁ this.gameObject.isStatic; // GameObject͕੩తମԽͲ͏͔? this.gameObject.layer; // GameObject͕ॴଐ͢ΔϨΠϠʔ໊ ࠲ඪΛॴ༗͠ͳ͍(BNF0CKFDUଘࡏ͠ͳ͍
2. MonoBehaviour
.POP#FIBWJPVSͱʁ (BNF0CKFDUʹ"UUBDI͢Δ4DSJQUͷجఈΫϥε ಛ -JGF$ZDMFΛ࣋ͭ 4UBSU 6QEBUF "XBLF 0O&OBCMFʜ (BNF0CKFDUͷγϣʔτΧοτΛ࣋ͭ
$PSPVUJOFΛ։࢝Ͱ͖Δ https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
-JGF$ZDMF Πϕϯτͷ࣮ߦॱং http://docs.unity3d.com/ja/current/Manual/ExecutionOrder.html ήʔϜͷॳظԽ "XBLF(BNF0CKFDU͕࡞ΒΕͨॳΊͷΈ 0O&OBCMF(BNF0CKFDU͕༗ޮʹͳΔͨͼʹݺΕΔ 4UBSU0O&OBCMF͞Εͨޙ
-JGF$ZDMF Πϕϯτͷ࣮ߦॱং http://docs.unity3d.com/ja/current/Manual/ExecutionOrder.html ཧఆ 0O$PMMJTJPO&OUFS $PMMJTJPODPMMJTJPO ͕͋ͨͬͨ࣌ 0O$PMMJTJPO&YJU $PMMJTJPODPMMJTJPO ʹ͋ͨͬͨޙ
0O5SJHHFS&OUFS $PMMJEFSDPMMJEFS ྖҬʹೖͬͨ࣌ 0O5SJHHFS&YJU $PMMJEFSDPMMJEFS ྖҬ͔Βग़ͨ࣌
-JGF$ZDMF Πϕϯτͷ࣮ߦॱং http://docs.unity3d.com/ja/current/Manual/ExecutionOrder.html ήʔϜϧʔϓ 6QEBUFຖϑϨʔϜݺΕΔ -BTU6QEBUF6QEBUFͯ͠$PSPVUJOFͷ࣮ߦऴྃޙ
-JGF$ZDMF Πϕϯτͷ࣮ߦॱং http://docs.unity3d.com/ja/current/Manual/ExecutionOrder.html ऴྃ࣌ 0O%JTBCMF(BNF0CKFDU͕"DUJWFͰͳ͘ͳͬͨλΠϛϯά 0O%FTUSPZ(BNF0CKFDU͕ফࣦ͢Δ࠷ޙͷλΠϛϯά
֤छϓϩύςΟ (BNF0CKFDUͷγϣʔτΧοτ࣋ͭ this.enabled; // εΫϦϓτ͕༗ޮԽͲ͏͔ this.isActiveAndEnabled; // εΫϦϓτ͕༗ޮͰGameObject͕༗ޮ͔ʁ this.gameObject;
// GameObjectͷࢀর this.tag; // λά this.transform; // زԿมܗΛߦ͏ object this.hideFlags; // this.name; // Inspector্Ͱදࣔ͞ΕΔ໊લ
$PSPVUJOFͷ։࢝Ͱ͖Δ public class SampleBehaviour : MonoBehaviour { void Start() {
this.StartCoroutine(Hoge()); } IEnumerator Hoge() { yield return null; } }
3. Resources
3FTPVSDFTͰ0CKFDUΛಡΈࠐΉ͜ͱ͕Ͱ͖Δ Sprite sprite = Resources.Load<Sprite>("image"); 6OJUZͰA3FTPVSDFTA͕ಛघϑΥϧμʹͳ͍ͬͯΔ 3FTPVSDFTҎԼʹ͋Δͷಡࠐ͕Մೳ ্l3FTPVSDFTJNBHFQOHzΛಡΈࠐΜͰ͍Δ
3FTPVSDFTͰ1SFGBCΛࢀর͢ΔࣄͰ͖Δ l3FTPVSDFT*UFNzΛࢀর GameObject _gameObject = Resources.Load<GameObject>("Item"); ಡΈࠐΈϑΥϧμɺ3FTPVSDFTͱ͍͏ϑΥϧμ໊Ͱ͋Εɺ Ͳͷ֊ʹ͍͍͋ͬͯ
4. Instantiate
(BNF0CKFDU*OTUBOUJBUFͰ 1SFGBCΛݩʹΦϒδΣΫτͷੜ͕Ͱ͖Δ GameObject _prefab = Resources.Load<GameObject>("CheckItem"); GameObject _object = Instantiate<GameObject>(_prefab);
ՃͰҾࢦఆ͕Ͱ͖Δ ୈೋҾ*OTUBOUJBUF͢Δ%࠲ඪ ୈࡾҾճసํ GameObject _object = Instantiate(_prefab, Vector3.zero, Quaternion.identity) as
GameObject;
Ճͨ͠(BNF0CKFDUͷ4FU1BSFOUͰࢦఆ _object.transform.SetParent(this.transform); _object.transform.SetParent(this.transform, false); ୈೋҾͰXPSME࠲ඪͷҐஔɾεέʔϧͰஔ͢Δ͔ʁ GBMTFࢦఆͨ͠ʹैଐɺ࣮ࡍͷҐஔɺεέʔϧ͕มΘΔ USVFXPSME࠲ඪ্ͷҐஔεέʔϧ͕มΘΒͳ͍Α͏ ࣗͷҐஔɺεέʔϧΛʹج͍ͮͯΛ࠶ܭࢉɻ
5. Destroy
4DFOFʹొͨ͠(BNF0CKFDUΛআ͢Δ͜ͱ͕Ͱ͖Δ // ҾʹGameObjectΛ͢͜ͱͰࣗΛআͰ͖Δ GameObject.Destroy(this.gameObject); // 1ඵޙʹআ͢Δ GameObject.Destroy(this.gameObject, 1.0f); ඵΛࢦఆͯ͠ɺͦͷޙʹআͰ͖Δ
6. Component
SampleBehaviour sample = this.gameObject.AddComponent<SampleBehaviour>(); (BNF0CKFDUʹଐ͢Δ$PNQPOFOUಈతʹՃͰ͖Δ SampleBehaviour sample = this.gameObject.GetComponent<SampleBehaviour>(); ·ͨऔಘͰ͖Δ
(FU$PNQPOFOU.POP#FIBWJPVSʹੜ͍͑ͯΔ (BNF0CKFDUʹ͍͍ͯΔ$PNQPOFOUͳΒͳΜͰऔಘՄೳ var text = this.GetComponent<Text>(); var trans = this.GetComponent<Transform>();
var collider = this.GetComponent<BoxCollider>();
ෳಉ͡$PNQPOFOU͕͋Δ߹ SampleBehaviour[] components = this.GetComponents<SampleBehaviour>(); SampleBehaviour component = this.GetComponentInChildren<SampleBehaviour>(); SampleBehaviour
component = this.GetComponentInParent<SampleBehaviour>(); ࢠཁૉ͔ΒऔಘͰ͖Δ ཁૉ͔ΒऔಘͰ͖Δ
ଞͷ$PNQPOFOUΛऔಘ͢Δํ๏ ࣗͷ(BNF0CKFDUʹ͚ͭͯࢀর ҉తಉҰγʔϯ QVCMJDͰઃఆͯ͠ࢀর ໌ࣔతಉҰγʔϯ
'JOEͰ୳ͯ͠ࢀর ҉తಉҰγʔϯ 4JOHMFUPOʹͯ͠ࢀর ҉తάϩʔόϧγʔϯ
'JOEͰ୳͢ GameObject obj1 = GameObject.Find("Sample"); GameObject obj2 = GameObject.FindGameObjectWithTag("Player"); GameObject
obj3 = GameObject.FindObjectOfType<GUITexture>(); جຊతʹUBHΛ͚ͭͯ୳͢ͷ͕ૣͯ͘ྑ͍ ͦͦ୳͞ͳ͍ͰࡁΉઃܭ͕Α͍
7. Input
public class SampleBehaviour : MonoBehaviour { void Update() { if
(Input.GetKey(KeyCode.Space)) { // εϖʔεΛԡͯ͠Δؒtrue } if (Input.GetKeyDown(KeyCode.Space)) { // εϖʔεΛԡԼͨ͠ॠؒͷΈtrue } if (Input.GetKeyUp(KeyCode.Space)) { // εϖʔεΛԡԼͯͨ͠͠ॠؒͷΈtrue } } } (FU,FZϘλϯೖྗΛऔಘ
(FU,FZϘλϯೖྗΛऔಘ Input.GetMouseButton(0); // ࠨΫϦοΫ Input.GetMouseButtonDown(1); // ӈΫϦοΫ Input.GetMouseButtonUp(2); // ਅΜதΫϦοΫ
// λονΠϕϯτͷॲཧ if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{ } TouchPhase.Began; // ։࢝ TouchPhase.Ended; // ऴྃ TouchPhase.Moved; // Ҡಈத TouchPhase.Stationary; // λονͨ͠··ఀࢭத TouchPhase.Canceled; // γεςϜଆͰΩϟϯηϧ͞Εͨ (FU5PVDIλονΠϕϯτͷऔಘ
Input.acceleration; // Ճ Input.location; // Ґஔใ Input.compass; // ίϯύε Input.deviceOrientation;
// σόΠεͷํ ͦͷଞऔಘͰ͖Δͷ
8. Debug
%FCVH-PH999Ͱϩά͕͚Δ Debug.Log("debugϩά"); Debug.LogWarning("warningϩά"); Debug.LogError("errorϩά");
Debug.Break(); Ұ࣌ఀࢭΛϓϩάϥϜଆ͔Β͢Δ͜ͱ͕ग़དྷΔ ͜Ε͕ԡ͞Εͨঢ়ଶ
Debug.isDebugBuild; // debugϏϧυͰ͋Εtrue %FCVHϏϧυ͔Ͳ͏͔ఆͰ͖Δ
$MFBSϩάΛআ͢Δ $PMMBQTFಉ͡ϝοηʔδͷϩάΛ·ͱΊΔ $MFBSPO1MBZ։࢝ϘλϯΛԡ͢ͱϩάΛΫϦΞ͢Δ &SSPSPO1BVTFΤϥʔ͕ى͖ͨΒϙʔζ͢Δ ͦͷଞ$POTPMFͷ͍ํ
9. Profile
(BNFϏϡʔͷ4UBUTΛԡ͢ͱ؆қతͳใ͕ݟΕΔ
8JOEPX1SPpMFSͰ$16/FUXPSL.FNPSZදࣔ