Unity延時方法Invoke和InvokeRepeating
阿新 • • 發佈:2017-12-05
執行 多少秒 int line deb avi delay 重復執行 gin
Unity延時方法Invoke和InvokeRepeating
MonoBehaviour裏面有兩個內置的延時方法
InvokeRepeating(methodName: string, time: float, repeatRate: float): void; methodName:方法名 time:多少秒後執行 repeatRate:重復執行間隔
Invoke(methodName: string, time: float): void; methodName:方法名 time:多少秒後執行
還有兩個重要的方法:
- IsInvoking:用來判斷某方法是否被延時,即將執行
- CancelInvoke:取消該腳本上的所有延時方法
using UnityEngine; using System.Collections; public class DelayScript : MonoBehaviour { //當前時間 private float nowTime; //執行重復方法的次數 private int count; // Use this for initialization void Start () { nowTime = Time.time; Debug.Log("時間點:"+nowTime);
Unity延時方法Invoke和InvokeRepeating