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);

}

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)