使用异步定时操作
// Start is called before the first frame update
async void Start()
{
isBool = true;
// await ScheduleTask();
}
// Update is called once per frame
async void Update()
{
if (isBool)
await ScheduleTask();
}
private bool isBool = false;
private readonly int mTime=5000;
public async Task ScheduleTask()
{
isBool = false;
await Task.Delay(mTime);
isBool = true;
Debug.Log($"{mTime} 已过去了");
}