change color
I have a trigger set up to changecolor -what am doing wrong?
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Target")
{
Debug.Log("hello");
col.GetComponent<Renderer>().material.SetColor=Color.red;
}
}
Comment
Best Answer
Answer by Jessespike · Jun 21, 2016 at 06:46 PM
I have a trigger set up to changecolor -what am doing wrong?
The error will describe what is wrong. You should include that so the question is clear. Chances are you are getting this error:
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
The error is saying you cannot assign SetColor as a variable or property. SetColor is a function, you need to pass the color as an argument.
https://docs.unity3d.com/ScriptReference/Material.SetColor.html
col.GetComponent<Renderer>().material.SetColor("_Color", Color.red);
There is a color property, which you may been trying to do:
col.GetComponent<Renderer>().material.color = Color.red;
Answer by Bentoon · Jun 21, 2016 at 06:33 PM
Got it .... Here: col.GetComponent().material.SetColor("_Color", Color.white);