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

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?

Have you written a script called Color yourself?

3 Answers

3

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

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.

  • Change your script to ColorManager.cs
  • If working with C# , make sure you change the script name in the code too