- Home /
how to check if gameobject has certain material.
im trying to set my boolean depending on the provided color to certain gameobjects.
var red:Material; var green:Material; var rightswitch:boolean;
function start(){
if (renderer.material == red){
print("ok");
rightswitch = false;
}else{
rightswitch = true;
}
}
Format your post. Do you get an error or what's the problem? Do you need to say Start() ins$$anonymous$$d of start() in JS?
renderer.material.name == red
Need to declare that you want to compare the name of the material, not the material itself.
If you want color though, then it would be
renderer.material.color == red
It's useful to look through the list of possible auto-completions that $$anonymous$$onodevelop gives you after typing a period.
The original comparison works fine, it is comparing if the current material on the renderer is the same material as the declared $$anonymous$$aterial variable Red is referencing.
The problem is probably what @getyour411 says, the start function is named wrong.
Answer by Crazy_Minecrafter · Jan 24, 2020 at 06:54 PM
Bruh 6 years late but here the solution for you
if(gameObject.gameObject.GetComponent<MeshRenderer>().material.ToString() == "material you want")
{
}