I’ve got some code designed to turn a forklift “on.” When it’s on, an emitter emits and an animation plays so that the forklift goes tearing down the road kicking up dust.
It works pretty well, as I can start and stop the animation. When I first click on the object, it kicks up the dust (the emitter is working). But after stopping it and trying to restart, the animation works again, but no dust.
Unity gives the following error:
MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.
The script I’m using is included below. I didn’t think i was destroying the emitter; so does anyone have an idea of what’s happening?
var Lift: GameObject;
var emitter: GameObject;
private var emitting : boolean = false;
private var emitted : boolean = false;
//check for input
function OnMouseUp (){
if (emitted)
EmitOn();
else
EmitOff();
}
//turning emitter on
function EmitOn() {
Lift.animation["C4D Animation Take"].speed=1;
emitting = true;
emitter.particleEmitter.emit = true;
emitting = false;
emitted = false;
}
//turning emitter off
function EmitOff() {
Lift.animation["C4D Animation Take"].speed=0;
emitting = true;
emitter.particleEmitter.emit = false;
emitting = false;
emitted = true;
}