Assigning material error

I am getting an error from the code below. I am trying to assign a sphere the color red, this code is exactly as it is in a tutorial. (Javascript)

code:

function Update () {

var colorRed : Color = Color.red;

renderer.material.color = colorRed;
	
}

Errors:

Assets/Custom_Scripts/Color.js(7,27): BCE0022: Cannot convert ‘Color’ to ‘UnityEngine.Color’.

Are you using: using System; ?

I am a beginner and I don’t know what you mean exactly. I restarted Unity and now I am only getting 1 error, so I deleted the second error from the post, if you were referring to that error.

BFGames might be right. Can you paste your whole code? Or at least the imports as well.

the code I posted is the entire code. I attached that script to the sphere primitive in the scene.

#pragma strict

import System;

var colorRed : Color = Color.red;

function Update () {
	
	renderer.material.color = colorRed;
}

you need to have “import System;” as well. It was using a different Color class than it was supposed to because you didn’t have the import. :slight_smile:

sorry for the delay. I am still getting an error, the red text is the problem. Here is all of the code:

import System;

function Update () {

var colorRed : Color = Color.red;

renderer.material.color = colorRed;

}

Error:

Assets/Custom_Scripts/Color.js(7,27): BCE0022: Cannot convert ‘Color’ to ‘UnityEngine.Color’.

Either change the name of your script to something else. Or change the script to the following.

You do not need import System;

You guys were thinking of UnityEngine.

function Update () {

var colorRed : UnityEngine.Color = UnityEngine.Color.red;

renderer.material.color = colorRed;

}

Nice catch, works now. So is it a rule that you can’t name a script the same name as a class?

Yeah exactly.