I my game you have to shoot asteroids, I have made it so that when you shoot an asteroid it changes its texture and them after yeilding destroys the object. Script attached to asteroid:
var explosion : Texture;
function OnCollisionEnter(col : Collision) {
if(col.gameObject.tag == "Laser"){ //if hit by player laser
renderer.material.mainTexture = explosion; //change texture
yield WaitForSeconds (0.07); // wait
Destroy (gameObject); // destroy object
}
}
However i get this error:
MissingReferenceException: The object of type ‘BoxCollider’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
Not sure how to fix this and it would be really great if you could help me sort this out.