foreach list gameobject random color
good guys days, I have a problem understanding on how I use the foreach loop and a list of gameobjects, expose the doubt with the following code.
Renderer rChunk; List list = new List(); //since prefab i want to randomice the color material foreach(Gameobject g in list){ rChunk = g.GetComponent(); rChunk.sharedMaterial.color = new Color(Random.Range(0.0f,1.0f),Random.Range(0.0f,1.0f),Random.Range(0.0f,1.0f));
}
okk, the problem is, i have always the same color, never is calculated a new color in each iteration, why?
Comment
Answer by Jessespike · May 06, 2016 at 05:04 PM
Insead of rChunk.sharedMaterial
use rChunk.material
.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080240im_/https://answers.unity.com/themes/thub/images/avi.jpg)