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;
}
}
2 Answers
2
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;
Got it …
Here:
col.GetComponent().material.SetColor(“_Color”, Color.white);
You are right, I edited my answer. It should work now :)
– Hellium