using System.Collections;
using UnityEngine;
using System;
public class Timer : MonoBehaviour
{
private bool doReturn = true;
public bool Ability(Action action, float time, string key,bool DoLoop)
{
if (Input.GetKeyDown(key)&&!DoLoop)
{
doReturn = true;
StartCoroutine(LateCall(time, action, DoLoop));
}
else if(Input.GetKeyDown(key) &&DoLoop)
{
//HERE IS THE PIECE OF CODE THATS MISSING!!!!
}
return doReturn;
}
private IEnumerator LateCall(float Duration, Action action,bool DoLoop)
{
action();
yield return new WaitForSeconds(Duration);
doReturn = false;
}
}
The basic usage of this code is to do an “ability” in my case call a function for a limited time, and some “abilities” need to be continuous or in this case the function needs to be looped for a time, I wanna keep the code as simple as possible.
The thing i can’t seem to find is how to loop an Action for a limited amount of time, also invoke didn’t seem to work.
The functions I’m using are in another class, the whole reason behind that is so I could make this a more universal script.