Toggle GameObject Visibility – Unity
if(gameObject.activeSelf){ gameObject.SetActive(false); }else{ gameObject.SetActive(true); }
if(gameObject.activeSelf){ gameObject.SetActive(false); }else{ gameObject.SetActive(true); }
Basically you just need to access the material property of the Renderer component. public Material yourMaterial; gameobject.GetComponent<Renderer> ().material = yourMaterial;