- Home /
Changing Game Objects Color
So I am currently just trying to change a game objects color to red, and I've been looking around on how to do so and I found this..
pickedNumber.gameObject.transform.renderer.material.color = new Color(4, 5, 5, 100);//C#
Now the issue is I don't really know how this works and I'm getting material.color underlined, because UnityEngine.Competent does not contain a definition for "material". Since I don't really know how this works and what the issue is if someone could explain this to me that would be awesome!
Answer by hbalint1 · May 01, 2015 at 05:19 PM
I assume you are using Unity 5. Now in Unity 5 you can't just access the components like properties, you have to look for them. you need to find your object's renderer component, then you can reach it's material to change the material's color property. So change it to:
pickedNumber.gameObject.GetComponent<Renderer>().material.color = Color.red;
sorry, the new forum doesn't allow me to write '>' sign, so a word was missing from answer. I updated it.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Material doesn't have a color property '_Color' 4 Answers
Assigning current color to a variable for fade out (C#) 0 Answers
How can i change the gameobject color based on RGBA 1 Answer
How to create a complex material in an Editor-Script? C# 0 Answers