- Home /
Change material color of array objects
Hi!
I want to have this kind of class selection system. So I need the classes who aren't highlighted to have a darker color and highlighted classes fully visible. I use this kind of blocky models so I need to store each body part to color it. I want to make it so I can use a array to change the color of all the objects in the array but I just get an error.
Here is my code: (Basically what you need I think)
public Color defaultColor;
public Color hoverColor;
public GameObject[] bodyPartsOfClass;
void Start () {
bodyPartsOfClass.renderer.materials[i].color = defaultColor;
}
void OnMouseOver () {
bodyPartsOfClass.renderer.material.color = hoverColor;
}
void OnMouseExit () {
bodyPartsOfClass.renderer.material.color = defaultColor;
}
Comment
Answer by Lo0NuhtiK · May 27, 2014 at 05:46 PM
Use a for-loop. eg :
for(int i = 0 ; i < bodyParts.Length ; i++)
bodyParts[i].color = whatever ;
Your answer
![](https://koobas.hobune.stream/wayback/20220613150027im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Array of Colors not working. 2 Answers
3 Colors on one plane 1 Answer