84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
|
using System.Collections;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.SceneManagement;
|
|||
|
using UnityEngine.UI;
|
|||
|
public class ManagerUI : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField] public GameObject player;
|
|||
|
[SerializeField] public GameObject gameOverPanel;
|
|||
|
[SerializeField] public Text gameOverText;
|
|||
|
[SerializeField] public Text restartText;
|
|||
|
[SerializeField] public Text HP;
|
|||
|
[SerializeField] public Text Energy;
|
|||
|
public bool isGameOver = false;
|
|||
|
private Droid playerDroid;
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
//Disactive le panneau et les textes si actives
|
|||
|
gameOverPanel.SetActive(false);
|
|||
|
gameOverText.gameObject.SetActive(false);
|
|||
|
restartText.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if(this.player == null)
|
|||
|
{
|
|||
|
this.isGameOver = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
playerDroid = this.player.GetComponent<Droid>();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//ai la touche G est press<73>e, lance la m<>thode StartCoroutine qui affiche le panneau avec le message Game Over etattends 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;
|
|||
|
Destroy(this.player);
|
|||
|
}
|
|||
|
//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.Q))
|
|||
|
{
|
|||
|
print("Application Quit");
|
|||
|
Application.Quit();
|
|||
|
}
|
|||
|
}
|
|||
|
if(isGameOver)
|
|||
|
{
|
|||
|
StartCoroutine(GameOverSequence());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
//la m<>thode GameOverSequence affiche le message GameOver puis attends 3 s<>conds et affiche le message <20>Press R to restart<72>
|
|||
|
private IEnumerator GameOverSequence()
|
|||
|
{
|
|||
|
HP.text="";
|
|||
|
Energy.text = "";
|
|||
|
gameOverPanel.SetActive(true);
|
|||
|
gameOverText.gameObject.SetActive(true);
|
|||
|
yield return new WaitForSeconds(3.0f);
|
|||
|
restartText.text = "Press R to restart";
|
|||
|
restartText.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public IEnumerator UpdateUI(int hpVal, int energyVal)
|
|||
|
{
|
|||
|
HP.text = "HP : " + hpVal;
|
|||
|
Energy.text = "Energy : " + energyVal;
|
|||
|
yield return new WaitForSeconds(0f);
|
|||
|
}
|
|||
|
}
|