Files
gold_dolphin/unity/Assets/Script/Tools/Timer.cs
2026-06-20 19:35:25 +08:00

40 lines
907 B
C#

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;
}
}