Done?
This commit is contained in:
64
Assets/Scripts/UI/GameplayUI.cs
Normal file
64
Assets/Scripts/UI/GameplayUI.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user