chip-game/Assets/Scripts/MovesAndTimeCounter.cs
2026-01-14 17:58:47 +03:00

61 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class MovesAndTimeCounter : MonoBehaviour
{
[SerializeField] TextMeshProUGUI movesLabel;
[SerializeField] string movesPrefix = "Ходы: ";
[SerializeField] TextMeshProUGUI timeLabel;
[SerializeField] string timePrefix = "Время: ";
[SerializeField] List<Graphic> graphicsToVisibility;
[SerializeField] int digitsAfterComma = 2;
private bool visible = false;
private GameManager gm;
public void SetVisibility(bool visible)
{
this.visible = visible;
foreach (Graphic g in graphicsToVisibility)
{
g.enabled = visible;
}
}
private void Start()
{
SetVisibility(false);
gm = GameManager.instance;
}
void Update()
{
if (!visible) return;
UpdateTime();
UpdateMoves();
}
private void UpdateTime()
{
float time = gm.vsBotThinkTime;
timeLabel.text = $"{timePrefix}{time.ToString($"F{digitsAfterComma}")}";
}
private void UpdateMoves()
{
movesLabel.text = movesPrefix + gm.vsBotMoves;
}
}