From ee6458f741b0e3681d1a55b50f64758898f8955e Mon Sep 17 00:00:00 2001 From: Jean-Luc NELET <jean-luc.nelet@etu.u-pec.fr> Date: Fri, 17 Jan 2025 13:20:51 +0100 Subject: [PATCH] =?UTF-8?q?T=C3=A9l=C3=A9verser=20les=20fichiers=20vers=20?= =?UTF-8?q?"/"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Obstacle.cs | 13 ++++++++++++ UIManager.cs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Obstacle.cs create mode 100644 UIManager.cs diff --git a/Obstacle.cs b/Obstacle.cs new file mode 100644 index 0000000..93134e8 --- /dev/null +++ b/Obstacle.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +public class Obstacle : MonoBehaviour +{ + private void OnCollisionEnter(Collision collision) + { + if (collision.gameObject.CompareTag("Rocket")) + { + Destroy(gameObject); // Détruit l'obstacle + Destroy(collision.gameObject); // Détruit la fusée + } + } +} diff --git a/UIManager.cs b/UIManager.cs new file mode 100644 index 0000000..9af73e2 --- /dev/null +++ b/UIManager.cs @@ -0,0 +1,59 @@ +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); + } +} \ No newline at end of file