Question by
bundoorahul · Mar 11, 2018 at 08:23 AM ·
gameobjectarrayrandom.rangerenderer.material.color
changing the color of a random game object not working
Hello, So i have an array storing cube gameobjects and i want to randomly select one game object from the array and change its color when the scene starts.
My code is as follows:
public GameObject[] cubesSame;
private GameObject manager;
int index;
void Start() {
manager = GameObject.FindGameObjectWithTag ("Game2Manager");
index = Random.Range (0, 12);
cubesSame[index].GetComponent<Renderer> ().material.color = Color.green;
}
When the game runs, the color of more than one cube changes. The script is attached to all the cube gameobjects. How could this issue be solved. I've been stuck on this for 2 days. Any help will be appreciated. Thanks
Comment