ClientServer/Client/Assets/Scripts/Player/DeathTimerController.cs

61 lines
1.3 KiB
C#
Raw Normal View History

2025-09-06 17:17:39 +04:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
//Thomas09
public class DeathTimerController : MonoBehaviour
{
public static DeathTimerController Instance;
[SerializeField] private Image fillImage;
private GameObject spectatedPlayerUIContainer;
[SerializeField] private TextMeshProUGUI timerText;
private float startTime = 10.0f;
private float currentTime = 0.0f;
[System.NonSerialized] public bool hasRecentlyDied;
private void Awake()
{
Instance = this;
Init();
}
private void Init()
{
spectatedPlayerUIContainer = transform.GetChild(0).gameObject;
}
private void OnEnable()
{
currentTime = startTime;
}
void Update()
{
if (currentTime > 0)
{
hasRecentlyDied = true;
currentTime -= Time.deltaTime;
fillImage.fillAmount = currentTime / startTime;
if (timerText != null)
timerText.text = ((int)currentTime).ToString();
}
else
{
ResetDeathTimer();
}
}
private void ResetDeathTimer()
{
spectatedPlayerUIContainer.SetActive(true);
gameObject.SetActive(false);
}
}