diff options
Diffstat (limited to 'ROUNDS/BackgroundHandler.cs')
-rw-r--r-- | ROUNDS/BackgroundHandler.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ROUNDS/BackgroundHandler.cs b/ROUNDS/BackgroundHandler.cs new file mode 100644 index 0000000..90823de --- /dev/null +++ b/ROUNDS/BackgroundHandler.cs @@ -0,0 +1,39 @@ +using System.Collections; +using UnityEngine; + +public class BackgroundHandler : MonoBehaviour +{ + private Background[] backgrounds; + + private float untilSwitch; + + private void Start() + { + backgrounds = GetComponentsInChildren<Background>(includeInactive: true); + } + + private void Update() + { + untilSwitch -= TimeHandler.deltaTime; + if (untilSwitch < 0f) + { + SwitchBackground(); + } + } + + private void SwitchBackground() + { + untilSwitch = Random.Range(30, 60); + for (int i = 0; i < backgrounds.Length; i++) + { + backgrounds[i].ToggleBackground(on: false); + } + StartCoroutine(StartBackGroundSoon()); + } + + private IEnumerator StartBackGroundSoon() + { + yield return new WaitForSeconds(5f); + backgrounds[Random.Range(0, backgrounds.Length)].ToggleBackground(on: true); + } +} |