diff --git a/Assets/Scripts/NotificationManager.cs b/Assets/Scripts/NotificationManager.cs index c770c2c..3b340c7 100644 --- a/Assets/Scripts/NotificationManager.cs +++ b/Assets/Scripts/NotificationManager.cs @@ -32,19 +32,19 @@ public class NotificationManager : MonoBehaviour { // Use this for initialization void Start() { delay = 0; - showingMessage = false; messages = new List(); text = GetComponent(); + hide(); } void Update() { if ( showingMessage ) { if ( Time.time > delay ) { - if ( messages.Count == 1 ) { - GetComponentInParent().enabled = false; - messages.Remove(messages[0]); - showingMessage = false; + if (messages.Count <= 1) { + messages.Remove(messages[0]); + hide(); } else { + messages.Remove(messages[0]); text.text = messages[0].getText(); delay = Time.time + messages[0].getDuration(); } @@ -60,7 +60,19 @@ public class NotificationManager : MonoBehaviour { GetComponent().text = text; delay = Time.time + duration; - GetComponentInParent().enabled = true; + show(); } } + + void show() { + GetComponentInParent().enabled = true; + text.enabled = true; + showingMessage = true; + } + + void hide() { + GetComponentInParent().enabled = false; + text.enabled = false; + showingMessage = false; + } } diff --git a/Assets/Scripts/UIController.cs b/Assets/Scripts/UIController.cs index 080cb3b..d9cec90 100644 --- a/Assets/Scripts/UIController.cs +++ b/Assets/Scripts/UIController.cs @@ -2,53 +2,74 @@ using System.Collections.Generic; using UnityEngine; -public class UIController : MonoBehaviour { +public class UIController : MonoBehaviour +{ GameObject score; GameObject pauseMenu; + [SerializeField] + NotificationManager notifications; + [SerializeField] GameObject gameOverPanel; [SerializeField] - private HealthbarController healthcontroller; + HealthbarController healthcontroller; - public void ShowPauseMenu() { + + public void ShowPauseMenu() + { pauseMenu.SetActive(true); } - public void ClosePauseMenu() { + public void ClosePauseMenu() + { pauseMenu.SetActive(false); } - public void LoadSceneByIndex(int index) { + public void LoadSceneByIndex(int index) + { Debug.Log("Loaded scene " + index); UnityEngine.SceneManagement.SceneManager.LoadScene(index); } - public void QuitGame() { + public void QuitGame() + { Debug.Log("Quit game"); Application.Quit(); } - public void ShowGameOverUI() { - if ( gameOverPanel != null ) { + public void ShowGameOverUI() + { + if (gameOverPanel != null) + { Canvas gameOverCanvas = gameOverPanel.GetComponent(); Debug.Log("Loading Canvas"); - if ( gameOverCanvas != null ) { + if (gameOverCanvas != null) + { Debug.Log("Loaded Canvas"); gameOverCanvas.enabled = true; - } else { + } + else + { Debug.Log("Gameover panel has no Canvas"); } - } else { + } + else + { Debug.Log("No game over panel assigned"); } } - public void InitHealthController(Player ply) { + public void InitHealthController(Player ply) + { healthcontroller.SetPlayer(ply); } + + public NotificationManager GetNotificationManager() { + return notifications; + } }