Hi, I’m trying to make some kind of slideshow in unity, but when I run the code, the object becomes pink. here’s the code ![]()
public GameObject l;
public Material l1;
public Material l2;
public Material l3;
// Use this for initialization
void Start () {
l = GameObject.Find("Screen");
StartCoroutine ("SwitchImage");
}
public IEnumerator SwitchImage() {
print ("1");
l.renderer.material = l1;
yield return new WaitForSeconds(1f);
print ("2");
l.renderer.material = l2;
yield return new WaitForSeconds(1f);
print ("3");
l.renderer.material = l3;
yield return new WaitForSeconds(1f);
I have asigned everything and there’s no errors in the console…
Thanks, Andreas.
EDIT: If I look at the scene while it’s at runtime, it seems like there is no texture at all…? just as if I had deleted it.
Does it print 1,2,3? If you select the Screen" object and watch, does the material change? For fun, test just the new materials: have start just say
– Owen-Reynoldsl.renderer.material = l2;(and don't call the Coroutine.) Does that work?Yes it says 1,2,3. I can't see the the material on the object while at runtime(just as if it was deleted), but in the Editor/scene the material works as it should. No it doesn't work even when executing the line in the start void and it's still pink when I run the game..
– AndreasX12If it won't work in Start, focus on that. Changing the material in Start, exactly the way you did, works fine for me. There's probably something else messing up the material. Could try it in a fresh scene by itself.
– Owen-ReynoldsOkay, it seems like using gameObject.renderer.material = l1; and put the script on the "Screen" fixed the issue, although some other random texture in my game became pink now (straaange) hehe, Thanks for the help :-)
– AndreasX12Same issue here and the material is assigned is inspector.
– admin_8C