- Home /
Waiting 2+ hours is insane.
Damage gets applied multiple times per frame
So I have a variable that gets set during my attack animation called applyDamage.
And in my code i have it set so that damage gets applied to the enemy when applyDamage is true, then sets applyDamage to false right after.
Even though I'm setting applyDamage to false immediately after actually applying the damage, the enemy still takes 10 damage, multiple times.
I should mention that this all takes place in the Update () function.
if (applyDamage) {
if (!appliedDamage) {
target.GetComponent<EnemyHealth>().TakeDamage(10);
appliedDamage = true;
applyDamage = false;
}
}
appliedDamage = false;
$$anonymous$$y guess is that the Update function gets called on multiple GameObjects or just that the animation is not perfectly in sync?
$$anonymous$$aybe try these things (just to make sure), maybe it does prevent this:
set Application.targetFrameRate to 60 so your Updates are not called more often than needed. Put this in one of you scripts in Awake or Start
Debug.Log(Time.frameCount + ": applyDamage is true!"); inside the first if
try putting all of these checks inside FixedUpdate();
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Root motion lost in transitions 1 Answer
Legacy animations, not playing 0 Answers
Animation stops rotation 0 Answers
2D (Movement and Animation) overlaps physics with RigidBody2D 1 Answer