65 lines
1.4 KiB
C#
65 lines
1.4 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using Objects;
|
|
|
|
public class GameplayUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject uiContainer;
|
|
[SerializeField] private TextMeshProUGUI timerText;
|
|
[SerializeField] private TextMeshProUGUI movesText;
|
|
[SerializeField] private GameObject winUI;
|
|
|
|
private float gameplayStart;
|
|
private int moves;
|
|
private bool isRunning;
|
|
|
|
private void Start()
|
|
{
|
|
winUI.SetActive(false);
|
|
uiContainer.SetActive(false);
|
|
GameManager.Instance.GameStateChanged += OnGameStateChanged;
|
|
Player.Instance.PlayerMoved += () => moves++;
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (isRunning)
|
|
{
|
|
// Debug.Log(Time.time - gameplayStart);
|
|
timerText.text = (Time.time - gameplayStart).ToString("F0");
|
|
movesText.text = moves.ToString();
|
|
}
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
{
|
|
GameManager.Instance.GameStateChanged -= OnGameStateChanged;
|
|
}
|
|
|
|
|
|
private void OnGameStateChanged(GameState newState)
|
|
{
|
|
bool isGameplay = newState == GameState.Gameplay;
|
|
|
|
uiContainer.SetActive(isGameplay);
|
|
winUI.SetActive(false);
|
|
|
|
if (isGameplay)
|
|
{
|
|
gameplayStart = Time.time;
|
|
moves = 0;
|
|
}
|
|
|
|
isRunning = isGameplay;
|
|
}
|
|
|
|
|
|
public void ShowWinScreen()
|
|
{
|
|
isRunning = false;
|
|
winUI.SetActive(true);
|
|
}
|
|
}
|