Post by AppThing on Dec 4, 2015 12:12:06 GMT
Hi,
I have an Enemy object with the Killable script attached. I have a Turret running a third party script that is aiming, shooting and sending damage to the killable (via raycasting). However when the Enemy is destroyed (de-spawned) the turret does not pick any other enemies because it's 3rd party script doesn't know how to detect that the target has been despawned.
So my question is what's the best method to detect this?
Additional Info / Stuff I've tried.
during the initial (3rd party script) DetectTarget method i have coded access to the killable script via:
Which i know works as later i call:
but I need to detect when the Enemy is "killed"...?
the 3rd party script uses:
But this does not seem to work if the Enemy is de-spawned rather than 'Destroyed'. and I have tried doing
but activeInHierarchy always = true
any pointers woud be gratefully received. I note there is a OnDespawned event mentioned in the docs, but I am not sure what I need to do in my script to subscribe to this event?
I have tried to simply put:
however I suspect I need to do something else to get the method to fire?? - help :-D
I have an Enemy object with the Killable script attached. I have a Turret running a third party script that is aiming, shooting and sending damage to the killable (via raycasting). However when the Enemy is destroyed (de-spawned) the turret does not pick any other enemies because it's 3rd party script doesn't know how to detect that the target has been despawned.
So my question is what's the best method to detect this?
Additional Info / Stuff I've tried.
during the initial (3rd party script) DetectTarget method i have coded access to the killable script via:
if(target == null)
{
target = otherGO.transform;
/* store the EnemyKillable script */
EnemyKillable = target.root.gameObject.GetComponent<Killable>();
}
Which i know works as later i call:
EnemyKillable.TakeDamage(myKillable.atckPoints.Value, myKillable);
but I need to detect when the Enemy is "killed"...?
the 3rd party script uses:
void OnTriggerExit(Collider other)
{
if(other.transform.root == target)
{
target = null;
}
}
But this does not seem to work if the Enemy is de-spawned rather than 'Destroyed'. and I have tried doing
if(!target.root.gameObject.activeInHierarchy) { target = null; }
but activeInHierarchy always = true
any pointers woud be gratefully received. I note there is a OnDespawned event mentioned in the docs, but I am not sure what I need to do in my script to subscribe to this event?
I have tried to simply put:
void OnDespawned () {
Debug.Log("I GOT DESPAWNED!! AWW");
target = null;
EnemyKillable = null;
}
however I suspect I need to do something else to get the method to fire?? - help :-D