renderer.material.color = Color.red; does not work

Well… The title explains…
Here’s the code:

function Update () {
	gameObject.renderer.material.color = Color.red;
}

Here’s the error. I just put the script on a standard Unity Cube.

NullReferenceException: Object reference not set to an instance of an object
Color.Update () (at Assets/Color.js:2)

1 Answer

1

You have called your script and class Color - this is hiding the built in Color - it looks like you also have a variable called Color.

Avoid calling things the same name as system classes.