How to get boolean value which change state in update function in collision function

I have a script where when player attack I set playerattack to true and after finishing attack animation a set the variable to false.


I use playerattack in collision function
If playerattack is true enemy get damage otherwise not
But I don’t know why I always get playerattack false

Firstly, you should copy-paste your code using code tags from the toolbar ribbon.

Second, to fix your issue, you are setting playerAttack to true and then immediately setting it to false a few lines later, which is essentially instantaneous. Since you mention you want it playerAttack to equal false after the animation, you can call that function at the end of your animation, like on the last frame.

If you haven’t done that before, look up Animation Events for Unity.

Thanks
Now problem is fixed with animation event

Love to hear it.