BlueGit

blue-star ggj-2020

Files

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

ModuleSpawnerController.cs

f93b9f9e History
ModuleSpawnerController.cs 1.2 KiB 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 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}