Can someone help me?
Hi devs, I have a problem. So I make 2d fighting game using Unity3D and when obly one character attacks the other player loses health, like he should. But as soon as both of the chracters hit each other ones, the next attack lowers the health of both characters. Both use the same hurtscript and the same code in different scripts as hitscript. Here is the gif. The hitscript for the left character:
void OnTriggerEnter2D(Collider2D coll){ //Hurtscript im animationscript
//Debug.Log (coll.name);
if ((coll.tag == "Player") && (!(coll.gameObject.name == "Bardock"))) {
coll.gameObject.GetComponent<hurtscript>().hurt(hurtvalue);
Debug.Log (coll.name);
}
The Hitscript of the right character:
void OnTriggerEnter2D(Collider2D coll){ //Hurtscript im Animationscript
Debug.Log (coll.name);
if ((coll.tag == "Player") && !(coll.gameObject.name == "Broly")) {
coll.GetComponent<hurtscript>().hurt(hurtvalue);
}
And the hurtscript they both share:
public class hurtscript : MonoBehaviour {
public int health = 10;
float dmgmultiplier;
public Image healthbar;
float fa = 1f;
//Animator anim; //l.10/11/15 braucht man erst wenn man eine hurtanimation einfügt
//int hurthash = Animator.StringToHash ("hurt");
void Start () {
//anim = GetComponent<Animator> ();
dmgmultiplier = 1f / health; //Berechnung eines lebensteins
Debug.Log (dmgmultiplier);
}
public void hurt(float hurtvalue){ //hurtvalue from the hitscript
float dmg = dmgmultiplier * hurtvalue; // berechnung des schadens
healthbar.fillAmount-= dmg ; // reduzierung des lebens um den schaden
//fa = fa - dmg; //aktualierung der fa variable aus der sich beim nächsten schaden den neuen lebnsstand ergibt
//anim.SetTrigger (hurthash); // spielen der hurtanimation (noch nicht vorhanden)
}
}
}
Thank you.
Your answer
Follow this Question
Related Questions
Trying to build in android but, missing architecture??? Cannot upload to PlayStore without it 0 Answers
Scriptable Object add damage not working 0 Answers
build post game does not open (mobile 2d) 0 Answers
stopping 1 animation and playing another 0 Answers
Google Sign in not working after publish 0 Answers