Téléverser les fichiers vers "/"

This commit is contained in:
Jean-Luc NELET 2025-01-17 13:20:51 +01:00
parent f89c8b5f6d
commit ee6458f741
2 changed files with 72 additions and 0 deletions

13
Obstacle.cs Normal file

@ -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
}
}
}

59
UIManager.cs Normal file

@ -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);
}
}