再生すると球型のオブジェクトをx.y.z軸に10個ずつ生成し、そのオブジェクトに赤、青、黄色、赤、青、黄色といったように順番にループするように色をつけていきたいです。オブジェクトを生成し赤色をつけるというところまではできたのですが、順番に色をつけるというところができません。
color.redやcolor.blueなどを使って色をつけていきたいです。
回答よろしくお願いします。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Copy5 : MonoBehaviour { 6 7 public GameObject Prefab; 8 9 // Use this for initialization 10 void Start() 11 { 12 for (int x = 0; x < 10; x++){ 13 for (int y = 0; y < 10; y++){ 14 for (int z = 0; z < 10; z++){ 15 var obj = Instantiate(Prefab, new Vector3(x * 1.0f, y * 1.0f, z * 1.0f), Quaternion.identity); 16 var renderer = obj.GetComponent<Renderer>(); 17 renderer.material.color = Color.red; 18 } 19 } 20 } 21 } 22 // Update is called once per frame 23 void Update () 24 { 25 } 26}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/04 16:58