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){


rightswitch = false;


rightswitch = true;



Bruh 6 years late but here the solution for you

if(gameObject.gameObject.GetComponent<MeshRenderer>().material.ToString() == "material you want")