diff options
author | Mikkel Bybjerg <mikkel.bybjerg@hotmail.com> | 2019-04-27 04:25:13 +0200 |
---|---|---|
committer | Mikkel Bybjerg <mikkel.bybjerg@hotmail.com> | 2019-04-27 04:25:13 +0200 |
commit | 8db39efb58e68f57404ec204f9dbe15e6157f1b0 (patch) | |
tree | d37470a9945b45d60134a36e90ec293c45895142 /nGJ2019/Assets/Scripts/ObstacleSpawner.cs | |
parent | b8c4567189d2d4f49d0331858519ac6455e1eb3d (diff) |
basic timeline spawning
Diffstat (limited to 'nGJ2019/Assets/Scripts/ObstacleSpawner.cs')
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 48 |
1 files changed, 48 insertions, 0 deletions
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)); + } +} |