64 lines
1.3 KiB
C#
64 lines
1.3 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class TurnTimerUI : MonoBehaviour
|
||
{
|
||
public Image timerBar; // сам бар
|
||
public float maxTime = 30f; // время таймера
|
||
private float currentTime;
|
||
private bool isRunning = false;
|
||
|
||
public GameManager gameManager;
|
||
|
||
private float originalWidth;
|
||
|
||
void Awake()
|
||
{
|
||
RectTransform rt = timerBar.rectTransform;
|
||
|
||
// Якорим и смещаем сверху
|
||
//rt.anchorMin = new Vector2(0.5f, 1f);
|
||
//rt.anchorMax = new Vector2(0.5f, 1f);
|
||
//rt.pivot = new Vector2(0.5f, 1f);
|
||
|
||
originalWidth = rt.sizeDelta.y;
|
||
|
||
StartTimer();
|
||
}
|
||
|
||
|
||
public void StartTimer()
|
||
{
|
||
currentTime = maxTime;
|
||
isRunning = true;
|
||
gameObject.SetActive(true);
|
||
}
|
||
|
||
public void StopTimer()
|
||
{
|
||
isRunning = false;
|
||
gameObject.SetActive(false);
|
||
}
|
||
|
||
public void ResumeTimer()
|
||
{
|
||
isRunning = true;
|
||
gameObject.SetActive(true);
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
if (!isRunning) return;
|
||
|
||
|
||
currentTime -= Time.deltaTime;
|
||
timerBar.fillAmount = Mathf.Clamp01(currentTime / maxTime);
|
||
|
||
if (currentTime <= 0f)
|
||
{
|
||
isRunning = false;
|
||
gameManager.EndPlayerTurn(); // Переход хода к боту
|
||
}
|
||
}
|
||
}
|