aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r--nGJ2019/Assets/Scripts/EventTimeline.cs28
-rw-r--r--nGJ2019/Assets/Scripts/Messenger.cs33
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleSpawner.cs6
3 files changed, 66 insertions, 1 deletions
diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs
index 21b0bdb..b864ae7 100644
--- a/nGJ2019/Assets/Scripts/EventTimeline.cs
+++ b/nGJ2019/Assets/Scripts/EventTimeline.cs
@@ -17,15 +17,30 @@ public class EventTimeline
this.type = type;
}
}
+
+ public class MessageEvent
+ {
+ public float time;
+ public String message;
+
+ public MessageEvent(float time, String message)
+ {
+ this.time = time;
+ this.message = message;
+ }
+ }
public event Action<SpawnEvent> OnSpawnEvent;
+ public event Action<MessageEvent> OnMessageEvent;
private List<SpawnEvent> futureEvents;
+ private List<MessageEvent> futureMessages;
private float currentTime;
public EventTimeline()
{
futureEvents = new List<SpawnEvent>();
+ futureMessages = new List<MessageEvent>();
currentTime = 0;
}
@@ -34,17 +49,28 @@ public class EventTimeline
futureEvents.Add(new SpawnEvent(time, height, type));
futureEvents.Sort((x,y) => x.time.CompareTo(y.time));
}
+
+ public void Add(float time, String message)
+ {
+ futureMessages.Add(new MessageEvent(time, message));
+ futureMessages.Sort((x,y) => x.time.CompareTo(y.time));
+ }
public void timeTick(float deltaTime)
{
currentTime += deltaTime;
- while(futureEvents.Count > 0 && currentTime > futureEvents[0].time)
+ while(futureEvents.Count > 0 && currentTime > futureEvents[0].time && futureMessages.Count > 0 && currentTime > futureMessages[0].time)
{
SpawnEvent e = futureEvents[0];
futureEvents.RemoveAt(0);
if(OnSpawnEvent != null)
OnSpawnEvent(e);
+
+ MessageEvent m = futureMessages[0];
+ futureMessages.RemoveAt(0);
+ if(OnMessageEvent != null)
+ OnMessageEvent(m);
}
}
}
diff --git a/nGJ2019/Assets/Scripts/Messenger.cs b/nGJ2019/Assets/Scripts/Messenger.cs
new file mode 100644
index 0000000..ca2ffe1
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/Messenger.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class Messenger : MonoBehaviour
+{
+ public Text MainText;
+ public ObstacleSpawner Spawner;
+ private EventTimeline timeline;
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ timeline = Spawner.GetEventTimeline();
+
+ timeline.Add(1, "Test");
+
+ timeline.OnMessageEvent += MessageOnEvent;
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+
+ void MessageOnEvent(EventTimeline.MessageEvent e)
+ {
+ MainText.text = e.message;
+ }
+}
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
index c285352..f438e85 100644
--- a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
+++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
@@ -8,6 +8,7 @@ public class ObstacleSpawner : MonoBehaviour
public GameObject caveWallsPrefab, rockTopPrefab, rockBottomPrefab, narrowPassagePrefab, rockJawsPrefab;
public LevelScrolling scrolling;
+ public Messenger messenger;
public float spawnLine;
@@ -63,4 +64,9 @@ public class ObstacleSpawner : MonoBehaviour
Gizmos.color = Color.green;
Gizmos.DrawLine(new Vector3(spawnLine, -10, 0), new Vector3(spawnLine, 10, 0));
}
+
+ public EventTimeline GetEventTimeline()
+ {
+ return timeline;
+ }
}