1
0
Fork 0

add R as restart Button when dead

This commit is contained in:
Jan 2018-04-23 13:17:59 +02:00
parent 411cc88812
commit 331024e8bb
2 changed files with 23 additions and 14 deletions

View file

@ -254,4 +254,8 @@ public class GameController : MonoBehaviour {
public UIController GetUI() { public UIController GetUI() {
return ui.GetComponent<UIController>(); return ui.GetComponent<UIController>();
} }
public bool GameEnded() {
return state == GameState.ENDED;
}
} }

View file

@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement;
public class UIController : MonoBehaviour public class UIController : MonoBehaviour
{ {
@ -17,31 +18,36 @@ public class UIController : MonoBehaviour
[SerializeField] [SerializeField]
HealthbarController healthcontroller; HealthbarController healthcontroller;
[SerializeField]
public void ShowPauseMenu() int mainMenuSceneIndex = 0;
{ int firstSceneIndex = 1;
void Update() {
if (Input.GetKey(KeyCode.R) && GameController.instance.GameEnded()) {
LoadSceneByIndex(firstSceneIndex);
}
}
public void ShowPauseMenu() {
pauseMenu.SetActive(true); pauseMenu.SetActive(true);
} }
public void ClosePauseMenu() public void ClosePauseMenu() {
{
pauseMenu.SetActive(false); pauseMenu.SetActive(false);
} }
public void LoadSceneByIndex(int index) public void LoadSceneByIndex(int index) {
{
Debug.Log("Loaded scene " + index); Debug.Log("Loaded scene " + index);
UnityEngine.SceneManagement.SceneManager.LoadScene(index); SceneManager.LoadScene(index);
} }
public void QuitGame() public void QuitGame() {
{
Debug.Log("Quit game"); Debug.Log("Quit game");
Application.Quit(); Application.Quit();
} }
public void ShowGameOverUI() public void ShowGameOverUI() {
{
if (gameOverPanel != null) { if (gameOverPanel != null) {
Debug.Log("Loaded Canvas"); Debug.Log("Loaded Canvas");
gameOverPanel.SetActive(true); gameOverPanel.SetActive(true);
@ -51,8 +57,7 @@ public class UIController : MonoBehaviour
} }
} }
public void InitHealthController(Player ply) public void InitHealthController(Player ply) {
{
healthcontroller.SetPlayer(ply); healthcontroller.SetPlayer(ply);
} }