if statement does not run i dont know why health goes neagtive.I had used A* ai for enemy.
When bullet hits enemy.enemy should deal damage.
public class EnemyHealth : MonoBehaviour
{
public int HpZombie;
public Slider hpbar_zombie;
public Transform player;
private Rigidbody2D rb;
bool shouldend;
// Start is called before the first frame update
void Start()
{
rb = this.GetComponent<Rigidbody2D>();
player = GameObject.FindGameObjectWithTag("Player").transform.GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
if (hpbar_zombie == null)
{
return;
}
Vector3 direction = player.position - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg-90f;
rb.rotation = angle;
if (HpZombie == 0)
{
//debug.log("hit") even this not works
Destroy(this.gameObject);
}
}
}