Change color (167771)

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;
          }
}

You are right, I edited my answer. It should work now :)

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;

Oops, yes, the new Vector3 should be removed. Try to decrease the value of factor to make a nice wave

Got it …
Here:
col.GetComponent().material.SetColor(“_Color”, Color.white);

cross post ... Thanks!

Getting there, thank you! Changed it slightly, otherwise it'd produce an error due to the new Vector3. They're not making the wave, but this should give the basis for it. I'll work on it to make them 'ordered'. Thanks again [81677-answer-2.png*_|81677] for (int i = 1; i < numberOfDots; i++) { Vector3 position = waveDots*.transform.position;* position.x = Mathf.Sin(Time.time + i * factor) * amplitude; waveDots*.transform.position = position;* } _*

Got it! Thank you for all the help! (: