Após o player morrer e pressionarmos o botão de restart, aparece, por um instante, a tela de pause. Após isso, ela fecha e o jogo começa. Porém, ao invés de tudo ficar normal, o player fica travado. Você consegue apertar as teclas para ele se mexer — ele faz até o som de andar/pular e até as animações — mas não sai do lugar.
public class UIManager : MonoBehaviour
{
[Header("Text")]
[SerializeField] private TextMeshProUGUI KeysText;
[SerializeField] private TextMeshProUGUI LifeText;
[Header("Panels")]
[SerializeField] private GameObject optionsPanel;
[SerializeField] private GameObject PausePanel;
[SerializeField] private GameObject GameOverPanel;
private void Awake()
{
PausePanel.SetActive(false);
optionsPanel.SetActive(false);
GameOverPanel.SetActive(false);
}
private void Start()
{
GameManager.Instance.InputManager.OnPause += OpenClosePauseMenu;
}
public void OpenClosePauseMenu()
{
if (PausePanel.activeSelf == false)
{
Time.timeScale = 0f;
GameManager.Instance.InputManager.DisablePlayerInput();
PausePanel.SetActive(true);
}
else
{
Time.timeScale = 1f;
GameManager.Instance.InputManager.EnablePlayerInput();
PausePanel.SetActive(false);
}
}
public void OpenOptionsPanel()
{
print("Set options to be opened");
optionsPanel.SetActive(true);
}
public void OpenGameOverPanel()
{
GameOverPanel.SetActive(true);
}
public void UpdateKeysLeftText(int totalValue, int LeftValue)
{
KeysText.text = $"Keys: {LeftValue}/{totalValue}";
}
public void UpdateLivesText(int amount)
{
LifeText.text = $"{amount}";
}
}
public class GameOverUI : MonoBehaviour
{
[SerializeField] private Button restartButton;
[SerializeField] private Button menuButton;
private void Awake()
{
restartButton.onClick.AddListener(RestartGame);
menuButton.onClick.AddListener(ReturnToMenu);
}
private void ReturnToMenu()
{
SceneManager.LoadScene("MainMenu");
}
private void RestartGame()
{
SceneManager.LoadScene("Gameplay");
}
}
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
public InputManager InputManager { get; private set; }
[Header("Managers")]
public UIManager UIManager;
public AudioManager AudioManager;
[Header("DynamicGameobject")]
[SerializeField] private GameObject BossDoor;
[SerializeField] private PlayerBehavior Player;
[SerializeField] private BossBehavior boss;
[SerializeField] private BossFightTrigger bossFightTrigger;
private int totalKeys;
private int LeftcollectedKeys;
[System.Obsolete]
private void Awake()
{
if (Instance != null)
{
Destroy(this.gameObject);
}
Instance = this;
totalKeys = FindObjectsOfType<CollectableKey>().Length;
LeftcollectedKeys = totalKeys;
InputManager = new InputManager();
UIManager.UpdateKeysLeftText(totalKeys, LeftcollectedKeys);
bossFightTrigger.OnPlayerEnterBossFight += ActivateBossBehavior;
Player.GetComponent<Health>().OnDead += HandleGameOver;
}
public void UpdateKeysLeft()
{
LeftcollectedKeys--;
UIManager.UpdateKeysLeftText(totalKeys, LeftcollectedKeys);
CheckAllKeysCollected();
}
private void CheckAllKeysCollected()
{
if (LeftcollectedKeys <= 0)
{
Destroy(BossDoor);
}
}
private void ActivateBossBehavior()
{
boss.StartChasing();
}
private void HandleGameOver()
{
UIManager.OpenGameOverPanel();
}