vendredi 20 août 2021

Change material on click Unity3D

I am trying to change material rendered on a cube upon click. Simple if else condition (I believe). I have tried

 void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Debug.Log("Click");

             if (GetComponent<Renderer>().material == brick)
                {
                Debug.Log("Brick");
                GetComponent<Renderer>().material = normal;

                }
            else if(GetComponent<Renderer>().material == normal)
                {
                Debug.Log("Normal");
                GetComponent<Renderer>().material = brick;
            }
              
        }
    }

I am getting in the first loop ie GetMouseButtonDown. But Nothing happens to the cube after that. no errors or warnings.enter image description here

Aucun commentaire:

Enregistrer un commentaire