I am making a Unity sword game. I have it so when you click Mouse0 it plays an animation and changes attacking to True. I am trying to make it so after two seconds(Or after the animation switches to Idle) it changes attacking to False. The code I have makes Unity stop responding.
EDIT: I know the code is in an infinite loop, but I need it so when ever I click mouse0 it works, not just at the beginning of testing. Is there a fix/ better way to do this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SwordSwing : MonoBehaviour
{
Animator anim;
public static bool attack = false;
private bool a = true;
void Start()
{
StartCoroutine(waiter());
anim = gameObject.GetComponent<Animator>();
}
IEnumerator waiter()
{
while(a = true)
if (Input.GetMouseButtonDown(0))
{
Debug.Log("True");
attack = true;
anim.SetTrigger("Active");
anim.SetTrigger("Idle");
yield return new WaitForSeconds(2);
attack = false;
Debug.Log("False");
}
}
}