I am using Unity3D in C# and am trying a simple script to change the material of an object. The initial material set works, but the change on the click of it does not do anything.
I know this is basic, and there are lots of questions on this topic here already, but all of them that i have seen, i have tried and not worked.
The program does not throw back any errors, the material simply does not change. i tried it with a texture instead and even a renderer.material.color at one point just to see if my files had problems. On the if statements i have tried == and =.

please help me find what I've done wrong, even if its a small typo i cant seem to see one.

here is my code:

```
using UnityEngine;
using System.Collections;

public class tilechange : MonoBehaviour {

public Material Grey;
public Material Black;

void Start()
{
    renderer.material = Grey;
}

void OnMouseDown () {
    if (renderer.material = Grey)
    {
        renderer.material = Black;
    }
    if (renderer.material = Black)
    {
        renderer.material = Grey;
    }
}
}

```

Any help would be appreciated :)

---

Update

I have added lots of debug.logs and it appears that the colour changes, then changes back. do you know how i could stop this happening?

here is a gif starting on grey and clicking. <http://gyazo.com/7c556ea79bb9b7277ae23d14ee44f8d2>

here is a gif starting on black and clicking. <http://gyazo.com/c6e00d858ab8d47436e689dd124bd762>

they both act differently, which seems like it could be something to do with the problem

---

Further Update

I tried adding in a third material and experimenting with the order of the if statements, the program runs through all of them, even if the materials are not used. and the material once clicked on always becomes that of the one in the last if statement.