added speed change and death

This commit is contained in:
MrTorex committed 2026-03-07 23:43:08 +03:00
1 parent 9e5f46b48c
commit 08e050ffd3
6 files changed
+1437 -5

No files matched your search

+72 -2
View File
@@ -1,5 +1,8 @@
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using PrimeTween;
namespace Code.UI
{
@@ -8,11 +11,32 @@ namespace Code.UI
public static GameplayController Instance;
[SerializeField] private TMP_Text coinsText;
[SerializeField] private CanvasGroup deathPanelCanvasGroup;
[SerializeField] private RectTransform deathPanelWindow;
[SerializeField] private TMP_Text finalResultText;
[SerializeField] private TMP_InputField nameInputField;
[SerializeField] private Button restartButton;
[SerializeField] private Button exitButton;
private int _coins;
private void Awake()
private void Awake() => Instance = this;
private void Start()
{
Instance = this;
Time.timeScale = 1;
if (deathPanelCanvasGroup != null)
{
deathPanelCanvasGroup.gameObject.SetActive(false);
deathPanelCanvasGroup.alpha = 0;
}
var player = GameObject.FindGameObjectWithTag("Player")?.GetComponent<Gameplay.Player.PlayerController>();
if (player != null) player.OnPlayerDeath += ShowDeathScreen;
restartButton.onClick.AddListener(RestartGame);
exitButton.onClick.AddListener(ExitGame);
}
public void AddCoin()
@@ -20,5 +44,51 @@ namespace Code.UI
_coins++;
coinsText.text = $"{_coins} Coins";
}
private void ShowDeathScreen()
{
deathPanelCanvasGroup.gameObject.SetActive(true);
Tween.Alpha(deathPanelCanvasGroup, startValue: 0f, endValue: 1f, duration: 0.5f, ease: Ease.OutSine, useUnscaledTime: true);
deathPanelWindow.localScale = Vector3.zero;
Tween.Scale(deathPanelWindow, endValue: 1f, duration: 0.6f, ease: Ease.OutBack, useUnscaledTime: true)
.OnComplete(() => {
Time.timeScale = 0;
});
finalResultText.text = $"You collected: {_coins} coins";
}
private void RestartGame()
{
SaveScore();
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
private void ExitGame()
{
SaveScore();
Time.timeScale = 1;
SceneManager.LoadScene("MainMenu");
}
private void SaveScore()
{
var playerName = nameInputField.text;
if (string.IsNullOrEmpty(playerName))
playerName = "Player";
Debug.Log($"Saved: {playerName} - {_coins}");
}
private void OnDestroy()
{
restartButton.onClick.RemoveAllListeners();
exitButton.onClick.RemoveAllListeners();
var player = GameObject.FindGameObjectWithTag("Player")?.GetComponent<Gameplay.Player.PlayerController>();
if (player != null) player.OnPlayerDeath -= ShowDeathScreen;
}
}
}