I want to code so that when I click on a GameObject, it changes colour with each click. For example, it starts off white: click to turn red, click again and it turns green, and so on and so forth until it get back to white.
I’ve got a single click working with Raycast. I’m guessing I’d need to do a string perhaps?
You need to declare an array of colors to cycle through, first:
Color[] colors = new Color[] {Color.white, Color.red, Color.green, Color.blue};
Then, after the objects is hit by your RC, you call the following code:
Color goColor = yourObject.renderer.material.color;
for(int i = 0; i < colors.Length; i++) {
if(goColor == colors *&& i == colors.Length - 1) {*
yourObject.renderer.material.color = colors[0]; Return; } else { yourObject.renderer.material.color = colors[i + 1]; Return; } } There are probably better ways to do it but that should get you started.