- Home /
Unity3d 'red' not regconized by 'Color'
For some reason unity3d wont regconize the Color.red; in my script
#pragma strict
function Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.renderer.material.color = Color.blue;
}
}
I've been trying to relearn unity coding, but the game engine says these colors arent apart of Color. I have no clue why this is, but any help would be great.
Come to this video for more information http://www.youtube.com/watch?v=_uiDhd5YX3s
I just tried the script, and it works fine. Compiles and changes the color as specified. Can you give us more information about the issues you are having?
Answer by pudd1nG · Apr 22, 2013 at 12:25 PM
Color.red is correct, are you sure you haven't got a script named 'Color.js' or 'Color.cs' in your project? That's the only reason I can see to this not working
Answer by anniyan137 · Apr 22, 2013 at 01:11 PM
I checked the video and it seems to me that you have created not one, but TWO scripts called Color. One is in CS and the other JS. Rename these scripts to something else and you should be good to go.
The ambiguity that arises due to similarly named scripts results in an error.
Answer by byteprogramming · Apr 22, 2013 at 12:27 PM
Change your script to ColorManager.cs
If working with C# , make sure you change the script name in the code too
Your answer
![](https://koobas.hobune.stream/wayback/20220613100805im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
Slowly fades from opaque to alpha 2 Answers
guitext is not changing color 1 Answer
How to change the color of the screen?? 3 Answers