BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / GAME / Scripts / ModuleSpawnerController.cs

ModuleSpawnerController.cs

92128f09 History
ModuleSpawnerController.cs 909 B Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5using UnityEngine.SceneManagement;
6
7public 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}