Last active
December 30, 2020 21:26
-
-
Save hidsh/4d85ee1001ac2011552d6be77f7c8fd8 to your computer and use it in GitHub Desktop.
unity-test: UnityのC#でインスタンスを取得しよう https://dkrevel.com/makegame-beginner/program-beginner-instance/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://dkrevel.com/makegame-beginner/program-beginner-instance/ | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
BoxCollider box = null; | |
Debug.Log(box); | |
box = GetComponent<BoxCollider>(); | |
Debug.Log(box); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
GameObject g = null; | |
Debug.Log(g); | |
g = GameObject.Find("Directional Light"); | |
Debug.Log(g); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
GameObject g = null; | |
Debug.Log(g); | |
g = GameObject.Find("Directional Light"); | |
Light l = null; | |
l = g.GetComponent<Light>(); | |
Debug.Log(l); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
Vector3 v = new Vector3(); // Vector3はclassではあるが、コンポーネントではない | |
// コンポーネントではないclassをインスタンス化するには new してやる必要あり | |
Debug.Log(v); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment