123456789101112131415161718192021222324252627282930313233343536 |
- using UnityEngine;
- using System.Collections;
- public class DelayCall : MonoBehaviour
- {
- public DelayCallDelegate callFunc;
- public float delay;
- private float startTime;
- // Use this for initialization
- void Start ()
- {
- startTime = GameTime.time;
- }
-
- // Update is called once per frame
- void Update ()
- {
- if(GameTime.time - startTime >= delay)
- {
- callFunc();
- Destroy(this.gameObject);
- }
- }
- public delegate void DelayCallDelegate();
- public static void Call(DelayCallDelegate callFunc, float delay)
- {
- GameObject gameObj = new GameObject("DelayCall");
- DelayCall delayCall = gameObj.AddComponent<DelayCall>();
- delayCall.delay = delay;
- delayCall.callFunc = callFunc;
- }
- }
|