This solution obfuscates the Coroutine, and uses Actions, which are generic callback functions.
Make a base class for your scripts that extends MonoBehavior. This will allow use of Coroutine.
using UnityEngine;
using System.Collections;
using System;
public class ExtendedBehavior : MonoBehaviour {
public void Wait(float seconds, Action action){
StartCoroutine(_wait(seconds, action));
}
IEnumerator _wait(float time, Action callback){
yield return new WaitForSeconds(time);
callback();
}
}
Then, in ExtendedBehavior classes, you can use Wait.
Wait (5, () => {
Debug.Log("5 seconds is lost forever");
});
↧