Hello
So I’m having a bit trouble with me shooting my enemies. When I shoot an enemy:
if (Physics.Raycast (muzzle.transform.position, muzzle.transform.TransformDirection (Vector3.forward), out hit)) {
Debug.DrawRay(muzzle.transform.position, muzzle.transform.TransformDirection (Vector3.forward), Color.red, 2);
if(hit.transform.tag == "Enemy")
{
GameObject.FindGameObjectWithTag("Enemy").GetComponent<GotHit>().BulletHit();
}
This method gets called:
public void BulletHit() {
if(transform.parent.gameObject.GetComponent<Unit>().Health > 0)
{
transform.parent.gameObject.GetComponent<Unit>().Health = transform.parent.gameObject.GetComponent<Unit>().Health - 100;
if(transform.parent.gameObject.GetComponent<Unit>().Health <= 0)
{
animation.Play("death3");
}
}
}
The weird thing(for me) is that the animation always plays on the first enemy in my project hierarchy. No matter what enemy I shoot. This is really confusing me. After the first enemy in my hierarchy dies, nothing seems to happen to any of the other enemies in my game, since it still just keeps calling to the same object.
Does anybody have any idea why my game is behaving like this?
Thanks in advance!