I have been getting a nagging error on pickup objects when they get destroyed.
I have attached a particle emitter to the object which gets detached before the object is destroyed but I'm not sure that this is influencing the problem since I turn off this section and still get the error.
I detach this of course, because I want to have something happen to show you picked something up, and it has to linger after the object is destroyed otherwise it will be destroyed immediately.
Here is the error:
MissingReferenceException: The object of type 'MeshCollider' 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.
if (hit.gameObject.tag == "TRASH_BEGIN" )
{
audio.PlayOneShot(goodSound);
var blah : GameObject = hit.gameObject;
var emitter : ParticleEmitter = hit.gameObject.GetComponentInChildren(ParticleEmitter);
if (emitter)
emitter.emit=true;
blah.transform.DetachChildren();
trashPickup ++;
if (trashPickup >= getExtraLIFE )
{
ScoreKeeper.lives++;
trashPickup = 0;
}
Destroy(hit.gameObject);
TemperatureGauge.temperatureAdjust = .05 ;
ScoreKeeper.timeLeft += 2;
yield WaitForSeconds(.25);
TemperatureGauge.temperatureAdjust = 0 ;
}
Has anyone seen this or can you point me in the right direction so I can clean this up?