71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
|
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;
|
||
|
[SerializeField] private Text lifeText;
|
||
|
[SerializeField] private Text fuseeText;
|
||
|
|
||
|
|
||
|
private bool isGameOver = false;
|
||
|
void Start() {
|
||
|
//Disactive le panneau et les textes si actives
|
||
|
gameOverPanel.SetActive(false);
|
||
|
gameOverText.gameObject.SetActive(false);
|
||
|
restartText.gameObject.SetActive(false);
|
||
|
lifeText.gameObject.SetActive(true);
|
||
|
fuseeText.gameObject.SetActive(true);
|
||
|
}
|
||
|
|
||
|
void Update() {
|
||
|
//ai la touche G est pressée, lance la méthode StartCoroutine qui affiche le panneau avec le message Game Over et attends 5 séconds puis affiche un deuxième message invitant le jouer à presser R pour relancer le jeu
|
||
|
if (Input.GetKeyDown(KeyCode.G) && !isGameOver) {
|
||
|
isGameOver = true;
|
||
|
StartCoroutine(GameOverSequence());
|
||
|
}
|
||
|
|
||
|
//si le jeu est terminé et on saisie 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();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//la méthode GameOverSequence affiche le message GameOver puis attends 3 séconds et affiche le message “Press R to restart”
|
||
|
public IEnumerator GameOverSequence() {
|
||
|
isGameOver = true;
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
public string UpdateLifeText(int life) {
|
||
|
lifeText.text = "Life: " + life;
|
||
|
return lifeText.text;
|
||
|
}
|
||
|
|
||
|
public string UpdateFuseeText(int nbFusee) {
|
||
|
fuseeText.text = "Nombre de fusées : " + nbFusee;
|
||
|
return fuseeText.text;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|