_xiaofang/xiaofang/Assets/Script/Manager/TimerMgr.cs

37 lines
1019 B
C#
Raw Normal View History

2024-10-24 12:46:20 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class TimerMgr : MonoBehaviour
{
public static TimerMgr Instance { get; private set; }
public GameObject cooldownTimerPrefab; // <20><>Inspector<6F><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
private GameObject timerpos;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject); // <20><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>֮<EFBFBD><EFBFBD><E4B2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else
{
Destroy(gameObject);
}
timerpos = GameObject.Find("Canvas");
}
public void StartCooldown(float cooldownTime, Action onFinished)
{
GameObject timer = Instantiate(cooldownTimerPrefab);
timer.transform.SetParent(timerpos.transform,false);
SkillCoolDownUI cooldownTimer = timer.GetComponent<SkillCoolDownUI>();
cooldownTimer.OnCooldownFinished += onFinished; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
cooldownTimer.StartCooldown(cooldownTime);
}
}