Hi, my problem is simple (please be patient, my knowledge of Unity isn’t too extensive). I have a turret gameObject which has 2 pieces, the head and base. The turret has to aim automatically at “zombies” that walk through a trigger that has been attached to the parent object. There are two scripts attached to the head: AimTurret and TurretParticleController.
AimTurret:
var target : Transform;
var aiming = false;
function Aim(newTarget : Transform)
{
target = newTarget;
transform.LookAt(target);
aiming = true;
}
function Return(original : Transform)
{
target = null;
transform.LookAt(original);
aiming = false;
}
function isAiming()
{
return aiming;
}
TurretParticleController:
function Start ()
{
var aimControl : AimTurret = GetComponent(AimTurret);
//Establish link to particle emitter and deactivate emission.
var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
for (var p : ParticleEmitter in particles)
{
p.emit = false;
}
//Once every frame update and check status.
while(true)
{
var isAiming = aimControl.isAiming();
for (var p : ParticleEmitter in particles)
{
p.emit = isAiming;
}
yield;
}
}
The aiming is working fine, and isAiming is also perfect. However when I run this, I get the following error:
MissingReferenceException: The object of type ‘ParticleEmitter’ 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.
I don’t know what I am supposed to do to fix it, and my particle emitter isn’t switching on and off like I want it to when the “Zombie” is inside the collider.
Thanks in advance for your help