名前を付ける方法ではないのですが、複製したインスタンスを識別する方法として。
Instantiate()はGameObjectを返すので、インスタント生成時にgameObjectに入れて、gameObject.tranceform.FindChid()で探しに行ってみてはどうでしょうか?
私も初心者なので、一応可能かどうか自分なりに試してみましたので、そのコードを書いておきますね。
ご参考までに。
C#
1using UnityEngine;
2using System.Collections;
3using UnityEngine.UI;
4
5public class test : MonoBehaviour
6{
7 //複数生成するので配列にしてみました
8 private GameObject[] obj;
9 //あらかじめインスペクターで割り当てておく
10 public GameObject prefab;
11
12 // Use this for initialization
13 void Start ()
14 {
15 obj = new GameObject[5];
16 for (int i = 0; i < obj.Length; i++) {
17 obj [i] = Instantiate (prefab, new Vector3 (10 + i * 110, 0, 0), transform.rotation) as GameObject;
18 }
19 Debug.Log (obj [3].transform.position.x);
20 Image img = obj [3].transform.FindChild ("Canvas/Image").GetComponent<Image> ();
21 img.color = new Color (1, 0, 0);
22 }
23
24 // Update is called once per frame
25 void Update ()
26 {
27
28 }
29}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/20 04:39