BCE0019: 'finalColor' is not a member of 'UnityEngine.Color'.

I’m trying to use a variable to change the material of an object.

it doesn’t seem to be working can anyone offer any advice.

below is a simplified version of my script, i’m new to scripting and probably missing something simple.


var finalColor : String = (" ");

function Start ()

{

var finalColor = (“red”); //i have a different formula i use to set this color, i’ve simplified it here.

this.renderer.material.color = Color.finalColor; // normally this would be = Color.red, but i’m trying to set it as a variable.

}

You can’t. Color is set in stone. If you want a variable, try this:

var finalColor : Color = Color.red;

function Start()
{
  // set you color up here
  renderer.material.color = finalColor; // don't need 'this'
}

If you need to use strings like “Red” you may need a Hashtable or switch statment to assign from string to Color;