From f2a3904b21bf47e6f20e17e2c8e7aa350a11980f Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 23 Apr 2018 18:37:03 +0200 Subject: [PATCH] small fix to NotificationManager, added message at gameStart --- Assets/Scripts/NotificationManager.cs | 33 ++++++++++++++------------- Assets/Scripts/PlayerMovement.cs | 8 ++++++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/NotificationManager.cs b/Assets/Scripts/NotificationManager.cs index 3b340c7..fa59bde 100644 --- a/Assets/Scripts/NotificationManager.cs +++ b/Assets/Scripts/NotificationManager.cs @@ -20,11 +20,11 @@ public class NotificationManager : MonoBehaviour { this.duration = duration; } - public string getText() { + public string GetText() { return text; } - public float getDuration() { + public float GetDuration() { return duration; } } @@ -34,43 +34,44 @@ public class NotificationManager : MonoBehaviour { delay = 0; messages = new List(); text = GetComponent(); - hide(); + Hide(); } void Update() { if ( showingMessage ) { if ( Time.time > delay ) { - if (messages.Count <= 1) { + Debug.Log(delay - Time.time); + Debug.Log(messages.Count); + if (messages.Count == 1) { messages.Remove(messages[0]); - hide(); - } else { + Hide(); + } else if (messages.Count > 1) { messages.Remove(messages[0]); - text.text = messages[0].getText(); - delay = Time.time + messages[0].getDuration(); + text.text = messages[0].GetText(); + delay = Time.time + messages[0].GetDuration(); } } } } - public void showMessage(string text, float duration) { - if ( showingMessage ) { - messages.Add(new Notification(text, duration)); - } else { - showingMessage = true; + public void ShowMessage(string text, float duration) { + messages.Add(new Notification(text, duration)); + if (!showingMessage) { + showingMessage = true; GetComponent().text = text; delay = Time.time + duration; - show(); + Show(); } } - void show() { + void Show() { GetComponentInParent().enabled = true; text.enabled = true; showingMessage = true; } - void hide() { + void Hide() { GetComponentInParent().enabled = false; text.enabled = false; showingMessage = false; diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 4989135..d15d4db 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -1,7 +1,8 @@ using UnityEngine; public class PlayerMovement : MonoBehaviour { - private bool firstKeyPressed; + bool firstKeyPressed; + bool messagePosted; [SerializeField] public float acceleration = 3; @@ -19,9 +20,14 @@ public class PlayerMovement : MonoBehaviour { // Use this for initialization void Start() { rb = GetComponent(); + messagePosted = false; } void Update() { + if (!firstKeyPressed && !messagePosted) { + messagePosted = true; + GameController.instance.GetUI().GetNotificationManager().ShowMessage("Press any key to start!", 2); + } if ( !firstKeyPressed && Input.anyKey ) { firstKeyPressed = true; }