- Home /
Color' does not contain a definition for 'red'
I'm trying to grab the color of a cube and change it over time using the lerp function But it says the color does not contain the definition for red and even for green.
public Color inicolor;
public Color redColor = Color.white;
public Color blackColor = Color.black;
void Awake()
{
inicolor = gameObject.GetComponent<Color>();
}
void Update ()
{
colorchanged ();
}
void colorchanged()
{
if (Input.GetKey (KeyCode.A)
inicolor = redColor;
else
inicolor = blackColor;
renderer.material.color = Color.Lerp(renderer.material.color,inicolor, Time.deltaTime * 5);
}
When you get the kind of error you describe, it is usually because you name one of your classes the same as a Unity class. So if the fixed that @tanoshimi indicates don't fix the problem, look for a class you created named 'Color' in your project, and change the name.
Answer by tanoshimi · Sep 20, 2014 at 07:24 PM
Does that script really generate that error? I don't see you attempting to use Color.red
anywhere. However, I do see other problems:
You're missing a ) on line 19.
You're trying to assign an object to a Color variable on line 6. Assuming the "Color" is the name of a script attached to the gameobject, and it has a public color variable called "color", then you want
inicolor = gameObject.GetComponent().color;
(however, it would be better to avoid using "color" as your class or variable names anyway)
@tanoshimi thanks a lot man it was the name of the script and also the braces...I'm a real beginner you know..