-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactBoxManager.cs
More file actions
48 lines (36 loc) · 1.24 KB
/
FactBoxManager.cs
File metadata and controls
48 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FactBoxManager : MonoBehaviour {
[SerializeField] private Transform factBoxParent;
[SerializeField] private FactBox[] factBoxes;
[SerializeField] private float factInterval = 3f;
private int i = 0;
// Start is called before the first frame update
void Start() {
factBoxes = factBoxParent.GetComponentsInChildren<FactBox>();
foreach (FactBox factBox in factBoxes) {
factBox.gameObject.SetActive(false);
}
factBoxes[0].gameObject.SetActive(true);
i++;
}
// Update is called once per frame
void Update() {
if (i >= factBoxes.Length) return;
StartCoroutine(NextFact());
}
private IEnumerator FirstFact() {
yield return new WaitForSeconds(factInterval);
factBoxes[0].gameObject.SetActive(true);
i++;
}
private IEnumerator NextFact() {
if (!factBoxes[i - 1].gameObject.activeSelf) {
Destroy(factBoxes[i - 1].gameObject);
yield return new WaitForSeconds(factInterval);
if (i < factBoxes.Length) factBoxes[i].gameObject.SetActive(true);
i++;
}
}
}