| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Linq; |
| 4 | using UnityEngine; |
| 5 | using UnityEngine.SceneManagement; |
| 6 | |
| 7 | public class ModuleSpawnerController : MonoBehaviour |
| 8 | { |
| 9 | private ModuleSlot[] slots; |
| 10 | private float timePerModule = 60; |
| 11 | public float SecondsRemainingUntilLoss = -1; |
| 12 | |
| 13 | void Start() |
| 14 | { |
| 15 | slots = GetComponentsInChildren<ModuleSlot>(); |
| 16 | |
| 17 | int moduleSpawns = Random.Range(1, slots.Length); |
| 18 | |
| 19 | SecondsRemainingUntilLoss = timePerModule * moduleSpawns; |
| 20 | |
| 21 | slots = slots.OrderBy(o => Random.value).ToArray(); |
| 22 | |
| 23 | for(int i = 0; i < moduleSpawns; i++) |
| 24 | { |
| 25 | slots[i].Spawn(); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | void Update() |
| 30 | { |
| 31 | bool win = true; |
| 32 | SecondsRemainingUntilLoss -= Time.deltaTime; |
| 33 | |
| 34 | foreach(ModuleSlot slot in slots) |
| 35 | { |
| 36 | if(slot.Module != null) |
| 37 | { |
| 38 | if (!slot.Module.ModuleFinalized) |
| 39 | win = false; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if(win) |
| 44 | { |
| 45 | SceneManager.LoadScene(1); |
| 46 | } |
| 47 | |
| 48 | if(SecondsRemainingUntilLoss <= 0) |
| 49 | { |
| 50 | SceneManager.LoadScene(2); |
| 51 | } |
| 52 | } |
| 53 | } |