aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Bybjerg <mikkel.bybjerg@hotmail.com>2019-04-27 04:25:13 +0200
committerMikkel Bybjerg <mikkel.bybjerg@hotmail.com>2019-04-27 04:25:13 +0200
commit8db39efb58e68f57404ec204f9dbe15e6157f1b0 (patch)
treed37470a9945b45d60134a36e90ec293c45895142
parentb8c4567189d2d4f49d0331858519ac6455e1eb3d (diff)
basic timeline spawning
-rw-r--r--nGJ2019/Assets/Scripts/EventTimeline.cs2
-rw-r--r--nGJ2019/Assets/Scripts/ObstacleSpawner.cs48
2 files changed, 49 insertions, 1 deletions
diff --git a/nGJ2019/Assets/Scripts/EventTimeline.cs b/nGJ2019/Assets/Scripts/EventTimeline.cs
index c6f2c24..1aef359 100644
--- a/nGJ2019/Assets/Scripts/EventTimeline.cs
+++ b/nGJ2019/Assets/Scripts/EventTimeline.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
public class EventTimeline
{
- public enum SpawnEventType {wall, enemy};
+ public enum SpawnEventType {alfa, beta};
public class SpawnEvent
{
diff --git a/nGJ2019/Assets/Scripts/ObstacleSpawner.cs b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
new file mode 100644
index 0000000..d007513
--- /dev/null
+++ b/nGJ2019/Assets/Scripts/ObstacleSpawner.cs
@@ -0,0 +1,48 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ObstacleSpawner : MonoBehaviour
+{
+ private EventTimeline timeline = new EventTimeline();
+
+ public GameObject alfaPrefab;
+ public GameObject betaPrefab;
+
+ public float spawnLine;
+
+ private void spawnOnEvent(EventTimeline.SpawnEvent e)
+ {
+ GameObject prefab = null;
+
+ if(e.type == EventTimeline.SpawnEventType.alfa)
+ prefab = alfaPrefab;
+
+ if(e.type == EventTimeline.SpawnEventType.beta)
+ prefab = betaPrefab;
+
+ Instantiate(prefab, new Vector3(spawnLine, e.height, 0), Quaternion.identity);
+ }
+
+ void Start()
+ {
+ timeline.Add(2, 2, EventTimeline.SpawnEventType.alfa);
+ timeline.Add(4, 2, EventTimeline.SpawnEventType.beta);
+ timeline.Add(5, -2, EventTimeline.SpawnEventType.beta);
+ timeline.Add(7, -3, EventTimeline.SpawnEventType.alfa);
+
+ timeline.OnSpawnEvent += spawnOnEvent;
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+ timeline.timeTick(Time.deltaTime);
+ }
+
+ void OnDrawGizmosSelected()
+ {
+ Gizmos.color = Color.green;
+ Gizmos.DrawLine(new Vector3(spawnLine,-10,0), new Vector3(spawnLine,10,0));
+ }
+}