I'm using UFPS in my FPS game. UFPS has a class vp_DamageHandler. It's attached to my target. Inside this class, there's:
public virtual void Die()
{
dieFunctionCalled = true; //the only thing I've added to this class, besides declaring dieFunctionCalled
...some UFPS code...//among other things, this is where the object is destroyed or deactivated
}
I want to keep the original files as clean as possible. I want to do my own coding in a different script to keep things tidy.
I want to do some other things when the target dies, so I've added myScript
to my target as well, and tried this:
void Update () {
if (GetComponent<vp_DamageHandler> ().dieFunctionCalled) {
GetComponent<vp_DamageHandler> ().dieFunctionCalled = false;
Debug.Log ("dieFunctionCalled");
}
}
The problem is that the target is destroyed before the dieFunctionCalled is set to true. So the moment the target dies, myScript is deactivated and doesn't log dieFunctionCalled
. If I would respawn the target, dieFunctionCalled
does show up in the console.
I've tried attaching myScript
to a empty GameObject, but then I get
Object reference not set to an instance of an object
Anyone who can help me with this? I'm new to Unity. Basically, all I want is to keep the original UFPS files as clean as possible, and write all my scripts in a different file.