using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class UIManager : MonoBehaviour { [SerializeField] private GameObject gameOverPanel; [SerializeField] private Text gameOverText; [SerializeField] private Text restartText; private bool isGameOver = false; void Start() { //Désactive le panneau et les textes si activés gameOverPanel.SetActive(false); gameOverText.gameObject.SetActive(false); restartText.gameObject.SetActive(false); } void Update() { if (Input.GetKeyDown(KeyCode.G) && !isGameOver) { isGameOver = true; StartCoroutine(GameOverSequence()); } //si le jeu est terminé et on saisit la touche R, le jeu est relancé if (isGameOver) { //If R is hit, restart the current scene if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } //la touche Q nous permet de sortir du jeu à tout moment if (Input.GetKeyDown(KeyCode.Q)) { print("Application Quit"); Application.Quit(); } } } // Nouvelle méthode publique pour déclencher le game over public void TriggerGameOver() { if (!isGameOver) { isGameOver = true; StartCoroutine(GameOverSequence()); } } //la méthode GameOverSequence affiche le message GameOver puis attend 3 secondes et affiche le message "Press R to restart" private IEnumerator GameOverSequence() { gameOverPanel.SetActive(true); gameOverText.gameObject.SetActive(true); yield return new WaitForSeconds(3.0f); gameOverText.text = ""; restartText.text = "Press R to restart"; restartText.gameObject.SetActive(true); } }