| 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 | |
| 11 | void Start() |
| 12 | { |
| 13 | slots = GetComponentsInChildren<ModuleSlot>(); |
| 14 | |
| 15 | int moduleSpawns = Random.Range(1, slots.Length); |
| 16 | |
| 17 | slots = slots.OrderBy(o => Random.value).ToArray(); |
| 18 | |
| 19 | for(int i = 0; i < moduleSpawns; i++) |
| 20 | { |
| 21 | slots[i].Spawn(); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | void Update() |
| 26 | { |
| 27 | bool win = true; |
| 28 | |
| 29 | foreach(ModuleSlot slot in slots) |
| 30 | { |
| 31 | if(slot.Module != null) |
| 32 | { |
| 33 | if (!slot.Module.ModuleFinalized) |
| 34 | win = false; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if(win) |
| 39 | { |
| 40 | SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); |
| 41 | } |
| 42 | } |
| 43 | } |