Cannot convert 'System.Type' to 'UnityEngine.Color'

I keep getting the error

   "**Cannot convert System.Type to UnityEngine.Color** "

I’m trying to create a custom cursor that should change color when it moves across an interactive object.

I have the cursor operating but changing color is an issue.

The code is originally from a Lesson Book taht i am working my way through called
" 3D Game Development with Unity"

I’ve read a lot of threads here but nothing seems to explain this issue…

Any help would be really appreciated… I’ve been at this for hours…

Here’s the code I have written so far…

        var controlCenter  : GameObject;
private var mouseOverColor : Color;
       

function Start (){
    guiTexture.enabled = false;  // disables the cursor on startup
    mouseOverColor = controlCenter.GetComponent(GameManager).mouseOverColor; //ref.p276
}
function Update () {
    // gets the curent cursor position
    var pos = Input.mousePosition;
    // feed its x and y  pos back into the GUI Texture cursor objects params.
    guiTexture.pixelInset.x = pos.x;
    guiTexture.pixelInset.y = pos.y - 32; // offset to top
}

function CursorColorChange (colorize: boolean){
	if (colorize) 
	 guiTexture.color = mouseOverColor;
	 
	 else guiTexture.color = Color.green;
 }

  //  END OF CODE

You haven’t specified which line of code is erroring out.

Is it this one?

mouseOverColor = controlCenter.GetComponent(GameManager).mouseOverColor;

You’ve specified in the posted script that mouseOverColor is of type Color, but I can’t tell the type of GameManager.mouseOverColor – it seems reasonable to assume that it is also (or should be) a Color.

That’s exactly your problem :wink:

var mouseOverColor = Color;

This line won’t create a variable of type Color. You don’t call the constructor of Color, you just assign the type Color to the variable. UnityScript automatically uses the typeof operator when you assign a type.

You have to use either:

// specify type without assigning a value
var mouseOverColor : Color;

or

// creating a new Color and let type-inference choose the type
var mouseOverColor = Color();
var mouseOverColor = new Color();
var mouseOverColor = Color.red;

a simple " : " should have been an " = "