Attack function animator problem
Hello, I have a problem with my attack function - When I press spacebar bool variable (impacted) should change to true and turn to false after attack animation is finished. However it looks like when I press spacebar first time or second that variable is not changing to true and this way if Im clicking fast spacebar I can deal damage to opponent 4 times at the beginning of the animation. Can you help me?
void Attack (){
mAnimator.ResetTrigger("attack");
if (Input.GetButtonDown("Attack")){
if (opponent != null)
{
transform.LookAt(opponent.transform.position);
//Impact();
if (!impacted)
{
opponent.GetComponent<Mob>().getHit(damage);
//impacted = true;
if (mAnimator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Standing_Melee"))
{
impacted = true;
}
}
}
mAnimator.SetTrigger("attack");
playerController.PlayerAttack = true;
}
if (!mAnimator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer.Standing_Melee")){
playerController.PlayerAttack = false;
impacted = false;
Debug.Log("Koniec animacji");
}
}
Comment
Your answer
Follow this Question
Related Questions
Animator not been initialized please help 0 Answers
any triple mouse click c# script? 2 Answers
Range Attack + Animation Script 0 Answers
Gaining experience from enemies killed? 1 Answer
Expanding Ring Attack 0 Answers