diff options
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/EventTimeline.cs | 2 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/ObstacleSpawner.cs | 48 |
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)); + } +} |