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
240
UnixTime is Simple
mattak
0
160
おっさんが停滞しないために
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
760
Unity energy usage
mattak
0
850
Unidux 0.3.1
mattak
1
360
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
C++でシェーダを書く
fadis
6
4.1k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
RubyLSPのマルチバイト文字対応
notfounds
0
120
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Facilitating Awesome Meetings
lara
50
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Building Your Own Lightsaber
phodgson
103
6.1k
GitHub's CSS Performance
jonrohan
1030
460k
Rails Girls Zürich Keynote
gr2m
94
13k
Navigating Team Friction
lara
183
14k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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දࣔ