66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
|
using System.Collections;
|
|||
|
using Unity.VisualScripting;
|
|||
|
using UnityEditor.SearchService;
|
|||
|
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;
|
|||
|
[SerializeField] private Text LifeText;
|
|||
|
[SerializeField] private Text FuseeText;
|
|||
|
void Start()
|
|||
|
{
|
|||
|
//Disactive le panneau et les textes si actives
|
|||
|
gameOverPanel.SetActive(false);
|
|||
|
gameOverText.gameObject.SetActive(false);
|
|||
|
restartText.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
void Update()
|
|||
|
{
|
|||
|
//ai la touche G est press<73>e, lance la m<>thode StartCoroutine qui affiche le panneau avec le message Game Over et
|
|||
|
//attends 5 s<>conds puis affiche un deuxi<78>me message invitant le jouer <20> presser R pour relancer le jeu
|
|||
|
if (Input.GetKeyDown(KeyCode.G) && !isGameOver)
|
|||
|
{
|
|||
|
isGameOver = true;
|
|||
|
StartCoroutine(GameOverSequence());
|
|||
|
}
|
|||
|
//si le jeu est termin<69> et on saisie la touche R, le jeu est relanc<6E>
|
|||
|
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 <20> tout moment
|
|||
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|||
|
{
|
|||
|
print("Application Quit");
|
|||
|
Application.Quit();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//la m<>thode GameOverSequence affiche le message GameOver puis attends 3 seconds et affiche le message <20>Press R to restart<72>
|
|||
|
public IEnumerator GameOverSequence()
|
|||
|
{
|
|||
|
isGameOver = true;
|
|||
|
gameOverPanel.SetActive(true);
|
|||
|
gameOverText.gameObject.SetActive(true);
|
|||
|
yield return new WaitForSeconds(3.0f);
|
|||
|
restartText.text = "Press R to restart";
|
|||
|
restartText.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public string LifeUp(int Life, int fusee)
|
|||
|
{
|
|||
|
FuseeText.text = "Nombre de Fus<75>e : " + fusee;
|
|||
|
LifeText.text = "LIFE : " + Life;
|
|||
|
return LifeText.text;
|
|||
|
}
|
|||
|
}
|