1
0
Fork 0

small fix to NotificationManager, added message at gameStart

This commit is contained in:
Jan 2018-04-23 18:37:03 +02:00
parent 2a0a4d5030
commit f2a3904b21
2 changed files with 24 additions and 17 deletions

View file

@ -20,11 +20,11 @@ public class NotificationManager : MonoBehaviour {
this.duration = duration; this.duration = duration;
} }
public string getText() { public string GetText() {
return text; return text;
} }
public float getDuration() { public float GetDuration() {
return duration; return duration;
} }
} }
@ -34,43 +34,44 @@ public class NotificationManager : MonoBehaviour {
delay = 0; delay = 0;
messages = new List<Notification>(); messages = new List<Notification>();
text = GetComponent<Text>(); text = GetComponent<Text>();
hide(); Hide();
} }
void Update() { void Update() {
if ( showingMessage ) { if ( showingMessage ) {
if ( Time.time > delay ) { 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]); messages.Remove(messages[0]);
hide(); Hide();
} else { } else if (messages.Count > 1) {
messages.Remove(messages[0]); messages.Remove(messages[0]);
text.text = messages[0].getText(); text.text = messages[0].GetText();
delay = Time.time + messages[0].getDuration(); delay = Time.time + messages[0].GetDuration();
} }
} }
} }
} }
public void showMessage(string text, float duration) { public void ShowMessage(string text, float duration) {
if ( showingMessage ) {
messages.Add(new Notification(text, duration)); messages.Add(new Notification(text, duration));
} else {
showingMessage = true;
if (!showingMessage) {
showingMessage = true;
GetComponent<Text>().text = text; GetComponent<Text>().text = text;
delay = Time.time + duration; delay = Time.time + duration;
show(); Show();
} }
} }
void show() { void Show() {
GetComponentInParent<Image>().enabled = true; GetComponentInParent<Image>().enabled = true;
text.enabled = true; text.enabled = true;
showingMessage = true; showingMessage = true;
} }
void hide() { void Hide() {
GetComponentInParent<Image>().enabled = false; GetComponentInParent<Image>().enabled = false;
text.enabled = false; text.enabled = false;
showingMessage = false; showingMessage = false;

View file

@ -1,7 +1,8 @@
using UnityEngine; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public class PlayerMovement : MonoBehaviour {
private bool firstKeyPressed; bool firstKeyPressed;
bool messagePosted;
[SerializeField] [SerializeField]
public float acceleration = 3; public float acceleration = 3;
@ -19,9 +20,14 @@ public class PlayerMovement : MonoBehaviour {
// Use this for initialization // Use this for initialization
void Start() { void Start() {
rb = GetComponent<Rigidbody2D>(); rb = GetComponent<Rigidbody2D>();
messagePosted = false;
} }
void Update() { void Update() {
if (!firstKeyPressed && !messagePosted) {
messagePosted = true;
GameController.instance.GetUI().GetNotificationManager().ShowMessage("Press any key to start!", 2);
}
if ( !firstKeyPressed && Input.anyKey ) { if ( !firstKeyPressed && Input.anyKey ) {
firstKeyPressed = true; firstKeyPressed = true;
} }