123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RandomDirLightManager : MonoBehaviour
- {
-
-
-
- [Tooltip("Time between each pulse. Should match the beats-per-second of the music. ")]
- public float secondsBetweenPulses = 0.5f;
-
-
-
- [Tooltip("How long to wait after start to start pulsing. Use to sync to music.")]
- public float startDelay = 0.1f;
-
-
-
- [Tooltip("Pool of colors that the lights could become on each pulse. ")]
- public List<Color> ColorOptions = new List<Color>();
-
-
-
-
- private float pulseTimer;
-
-
-
- private List<Light> lightList;
-
-
-
- private List<RandomDirectionMover> randPointerList;
-
-
-
-
- private int lastcolorindex = -1;
-
- void Start ()
- {
- lightList = new List<Light>(GetComponentsInChildren<Light>());
- randPointerList = new List<RandomDirectionMover>(GetComponentsInChildren<RandomDirectionMover>());
- pulseTimer = -startDelay;
- }
-
-
- void Update ()
- {
- pulseTimer += Time.deltaTime;
- if(pulseTimer > secondsBetweenPulses)
- {
- PulseLights();
- pulseTimer = pulseTimer % secondsBetweenPulses;
- }
- }
-
-
-
- private void PulseLights()
- {
- if (ColorOptions.Count > 0)
- {
- int newcolorindex;
- if (ColorOptions.Count > 1)
- {
- newcolorindex = Random.Range(0, ColorOptions.Count - 1);
- while (newcolorindex == lastcolorindex)
- {
- newcolorindex = Random.Range(0, ColorOptions.Count - 1);
- }
- lastcolorindex = newcolorindex;
- }
- else newcolorindex = 0;
-
- foreach(Light light in lightList)
- {
- light.color = ColorOptions[newcolorindex];
- }
- }
- foreach(RandomDirectionMover pointer in randPointerList)
- {
- StartCoroutine(pointer.NewDirection());
- }
- }
- }
|