プレハブからインスタンス化されたものを色付けしたいですがうまくいきません。
public class Script : MonoBehaviour { private float timer = 0.0f; public GameObject Prefab; public GameObject a; void Update () { timer += Time.deltaTime; if(timer >= 2){ timer = 0.0f; Vector3 offset = new Vector3 (0, 0, 0); a = Instantiate (Prefab, transform.position + offset, transform.rotation) as GameObject; if (timer >= 4) { a.GetComponent<Renderer> ().material.color = Color.red; } } } } コード
このコードを加えればいいとは思うのですがただ加えるとobject reference not set to an instance of an object のエラーが出てしまいます。
どうすればプレハブから出てきたものでも色をつけられますか?
回答1件
あなたの回答
tips
プレビュー