Question by
SteakSchaf · Sep 17, 2019 at 07:22 AM ·
multiplayerplayerdamage
Both players take damage when hit?,both players take damage
Hello i'm new to unity and am working on a little 2d fighting game but i have a little problem. i already have health bars for the 2 players but the problem is every time TakeDamage() is called, both charackters take damage. Here is the essential code so far, both have diffrent scipts but nearly the same context:
public Image HealthBar;
public float health= 100;
public void TakeDamagel (float amount){
health -= amount;
HealthBar.fillAmount = health/ 100f;
if(health <= 0)
{
Die();
}
}
void OnTriggerEnter2D (Collider2D other){
if (other.gameObject.name.Equals("Colm")){
TakeDamagel(10);
}
}
void Die(){
anim.SetBool ("isWalking", false);
anim.SetTrigger ("Die");
}
}
Comment