- Home /
Question by
Sami_Pal · Feb 16, 2018 at 05:20 PM ·
materialrenderermouseclickmeshrenderer
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;
}
}
Comment
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
How to change a specific material of an object at runtime ? 2 Answers
appear/disappear gameobject 3 Answers
I cant turn off my mesh renderer for some reason 3 Answers
SetFloat doesn't work 1 Answer