1
This commit is contained in:
39
unity/Assets/Script/Tools/Timer.cs
Normal file
39
unity/Assets/Script/Tools/Timer.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Timer : MonoBehaviour
|
||||
{
|
||||
private float timer;
|
||||
private Action action;
|
||||
private bool timeIsDone;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timer > 0 && !timeIsDone)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer <= 0)
|
||||
{
|
||||
action?.Invoke();
|
||||
timeIsDone = true;
|
||||
|
||||
ManagersMode.Poll.UnSpwan("Timer","timer",this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建计时器
|
||||
/// </summary>
|
||||
/// <param name="timer">计时时间</param>
|
||||
/// <param name="cllBackAction">回调函数</param>
|
||||
public void CreateTime(float timer,Action cllBackAction, bool timeIsDone = false)
|
||||
{
|
||||
this.timer = timer;
|
||||
this.action = cllBackAction;
|
||||
this.timeIsDone = timeIsDone;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user