I use this coroutine to hide a car mesh for a few seconds when its loaded, but Unity keeps telling me the object of type MeshRenderer has been destroyed, and that the line: " carRenderers*.enabled=true;" is trying to access it even though a put a null check in front of it and the array isnt empty…*
I call the corountine in a function that loads the car, which in turn is called in start()…
-
IEnumerator hideCarForSeconds(int seconds){*
-
//hide car*
-
for(int i=0;i<carRenderers.Length;i++)*
-
{*
_ carRenderers*.enabled=false; _
_ } _
_ yield return new WaitForSeconds(seconds); _
_ //show car*_
* if(carRenderers!=null){*
* for(int i=0;i<carRenderers.Length;i++)*
* {*
_ carRenderers*.enabled=true;
}
}
}*_