Hey all, heres my snippit of code. I am trying to play attack animation when you press P and set “attacking” to true. and leave it as true while the animation is playing. Also wanted to use the delay as a “stun” so the player doesnt move or do anything to cancel the animation while its still playing. but currently if I spam P I just keep interrupting the attack animation.
Am i using the delay wrong? I was under the impression that as soon as I set the delay with StartCoroutine nothing else in the code will run but my Update() seems to still be looping.
Thanks!
Animator anim;
public bool attacking = false;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown("p")) {
attacking = true;
anim.SetTrigger("Attack1Trigger");
StartCoroutine (COStunPause(1.2f));
attacking = false;
}
}
public IEnumerator COStunPause(float pauseTime)
{
yield return new WaitForSeconds(pauseTime);
}