0

I've been trying to change the Colour of the cube when it's triggered, basically when the cube is on top of the plane (Checkpoint). I've applied Standard Material to the plane, changed the Albedo property to blue colour and nothing seems to be happening. I know it's very simple but seems like I'm missing something here? Any help would be appreciated.

public class Checkpoint : MonoBehaviour 
{
    Renderer colorRenderer;

    public void Start()
    {
        colorRenderer = GetComponent<Renderer>();
    }

    public void OnTriggerEnter(Collider collider)
    {
        if(collider.gameObject.tag == "Player")
        {
            colorRenderer.material.SetColor("_Color", Color.green);

            Debug.Log("Checkpoint Reached");
        }
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
Shafee
  • 95
  • 1
  • 10
  • 1
    Possible duplicate of [Unity3D: How to change Transform's (GameObject's) color?](https://stackoverflow.com/questions/33007575/unity3d-how-to-change-transforms-gameobjects-color) – Ali Kanat Mar 19 '19 at 15:28
  • 1
    is one of the colliders a **trigger**? Did you check if the method is called at all? you rather should set the color via `colorRenderer.material.color = Color.green;` – derHugo Mar 19 '19 at 15:34

1 Answers1

0

Yikes! I forgot to set the GameObject to trigger. It's working fine now.

Shafee
  • 95
  • 1
  • 10