Changing gameobject material via mouse click not working

When I click on some gameObject, I want the material of another gameObject to change and to be more exact I want to constantly change between two materials.


    public GameObject rock;
    public Material blueMat;
    public Material redMat;
    Material currentMat;

	void Update () { 
         // it's blue at first, but it should gets updated after clicks
         currentMat = rock.GetComponent<Renderer>().material; 
    }
    void OnMouseDown()
    {
        if (currentMat.name.Equals("red")){
            rock.GetComponent<Renderer>().material = blueMat;
        }else if(currentMat.name.Equals("blue")) {
            rock.GetComponent<Renderer>().material = redMat;
        }
    }

Figured it out thanks to this guy , I should’ve used sharedMaterial instead of material