Adding a life on collision, otherwise subtract

Hello everybody,

I typed a really long question and realized it was boring, so this is a summary:

  • My enemy has two hitpoints.
  • if it dies it instantiates a particle system
  • It can happen you only hit it once
  • Enemy must be destroyed at some point if you failed to shoot it twice
  • Enemy collides with my box which should destroy it, showing a different particle
  • Because of collision, 1 hitpoint is subtracted, therefore now showing 2 particle systems
  • Tried adding life on specific collision so it doesn’t show first particle system
  • Doesn’t work

I attached this script to my enemy:

function OnCollisionEnter (collision : Collision){
	life --;
	if(life == 0){
	Instantiate(RedBurst2, transform.position, transform.rotation);
	Instantiate(plusone, transform.position, transform.rotation);
	if(collision.gameObject.tag == "border"){
		Instantiate(RedBurst, transform.position, transform.rotation);
		Instantiate(minustwo, transform.position, transform.rotation);

I left out the vars, they speak for themselves. Can someone point out the error? I feel like it’s something really stupid.


I don’t get the meaning of “target” and “zombie” in your script. Is zombie the enemy itself? If so, you should do Destroy(gameObject) (and, of course, instantiate the particle systems BEFORE the Destroy() call).

By the way, posting the exact error you get could make the things more clear! :wink: