I've noticed if I kill an object with the health script, while having damage zone

sneekyo

Member
I've noticed if I kill an object with the health script and the health script deactivates the object, while having damage zone script attached to that object it keeps doing damage to the player infinitely until the player dies
 
That is a general Unity issue. The damage zone uses the trigger enter/exit mechanism. When you deactivate the object with a trigger collider attached, it will not trigger the OnTriggerExit event upon deactivation. So the script continues to damage the character.
 
Could I write some kind of script that sends the ontrigger exit event, when the damage zone is deactivated? What would you do?
 
You can't send an OnTriggerExit event manually. You can copy the DamageZone script to your own namespace (I would not recommend modifying the original). Then you can register the player collider on trigger enter, and add an OnDisable method. Here you can call the OnTriggerExit method with the registered player collider.
 
Top