Files
SpaceDroid/My project/Assets/Script/UIManager.cs
2025-01-17 13:10:42 +01:00

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é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.Escape))
{
print("Application Quit");
Application.Quit();
}
}
}
//la méthode GameOverSequence affiche le message GameOver puis attends 3 seconds 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);
restartText.text = "Press R to restart";
restartText.gameObject.SetActive(true);
}
public string LifeUp(int Life, int fusee)
{
FuseeText.text = "Nombre de Fusée : " + fusee;
LifeText.text = "LIFE : " + Life;
return LifeText.text;
}
}