Hi.
I'm trying to write a script for my enemy. When shooting the enemy this script has to count when the bullet enters and leaves the box collider. I want to add a maximum of two shots that just fired at the enemy should make the death animation and then after 4 seconds is destroyed.
Now it happens that firing only one shot the enemy is destroyed after 4 seconds, but does not do the animation death.
Some help?
script:
using UnityEngine;
using System.Collections;
public class EnemyDead: MonoBehaviour {
public float count = 2;
public Animator Animator;
void Start () {
Animator = GetComponent ();
}
void OnTriggerEnter2D(Collider2D col)
{
if(col.gameObject.tag == "HitEnemy");
}
void OnTriggerExit2D(Collider2D col)
{
count = -1;
if(count > 0)
Animator.SetInteger ("AnimState", 3);
Destroy(gameObject, 4);
}
}
↧