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
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
CSC509 Lecture 09
javiergs
PRO
0
140
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Jakarta EE meets AI
ivargrimstad
0
670
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
Contemporary Test Cases
maaretp
0
140
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Quine, Polyglot, 良いコード
qnighy
4
650
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
A Modern Web Designer's Workflow
chriscoyier
693
190k
Rails Girls Zürich Keynote
gr2m
94
13k
Embracing the Ebb and Flow
colly
84
4.5k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
The Invisible Side of Design
smashingmag
298
50k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Code Review Best Practice
trishagee
64
17k
Designing for humans not robots
tammielis
250
25k
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දࣔ