this is the problem
when character is idle, i want to start coroutine once, and when user presses any button, i want to stop the coroutine once. problem is code to check if user is in idle or moving is in update function.
this is my solution
private void Update()
{
CheckIdle();
}
private bool MoveCheck, TimerCheck;
private void CheckIdle()
{
MoveCheck = Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal") == 0;
if (MoveCheck) // character is in idle
{
if (!TimerCheck) // timer has not started yet
{
TimerCheck = true; // timer started
StartCoroutine(Idling());
}
}
if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
{
if (TimerCheck) // timer is on
{
TimerCheck = false; // stop timer
StopCoroutine(Idling());
}
}
}
this works well but code looks messy. is there any simpler way to do it? can event and delegate help me in this scenario ? if yes, how ?