GetGameObject.csUnity記事: 目次
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using UnityEngine; /// <summary> /// /// Unity 2018.2.15f1 /// /// </summary> public class GetGameObject : MonoBehaviour { // Use this for initialization private void Start() { // 1. タグで取得する GameObject gameObject1 = GameObject.FindGameObjectWithTag("Knohhoso"); // 2. パスで取得する (高負荷・低速) GameObject gameObject2 = GameObject.Find("/GameObject1/GameObject2"); // 3. オブジェクト名で取得する (高負荷・低速) GameObject gameObject3 = GameObject.Find("GameObject3").gameObject; // 取得できたかチェック Debug.Log("gameObject1: " + gameObject1.name); Debug.Log("gameObject2: " + gameObject2.name); Debug.Log("gameObject3: " + gameObject3.name); } } |