Is it possible to pass a function as an argument ?
I’ve tried searching for this but I find things that are not related to what I’m looking for.
I’ve got a coroutine used to fill a progression bar. As long as the player hold the action key, the process carry on.
When the progress bar is full, the coroutine trigger a function.
It look like this :
IEnumerator ProgressBar(RaycastHit hit)
{
int actionProgress = 1;
while((Input.GetButton("Action"))){
yield return new WaitForSeconds(0.03f);
actionProgress++;
if(actionProgress >= 100) doSomething(hit);
yield return null;
}
}
Now I want to use this coroutine for multiple action, opening a door, planting a bomb or whatever.
Is it possible to call my function like this :
StartCoroutine(ProgressBar(hit, some-function);
IEnumerator ProgressBar(RaycastHit hit, Function func)
{
int actionProgress = 1;
while((Input.GetButton("Action"))){
yield return new WaitForSeconds(0.03f);
actionProgress++;
if(actionProgress >= 100) func(hit);
yield return null;
}
}