Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Light pointLight; // The light component of the firefly
- private float minLuminosity = 0; // min intensity
- private float maxLuminosity = 1; // max intensity
- private float luminositySteps = 0.005f; // factor when increasing / decreasing
- private float shineDuration = 3; // wait 3 seconds when faded in
- private void Start()
- {
- pointLight = GetComponent<Light>();
- pointLight.intensity = Random.Range(minLuminosity, maxLuminosity); // start with a random intensity
- StartCoroutine(ChangeIntensity()); // start the process
- }
- private IEnumerator ChangeIntensity()
- {
- pointLight.intensity += luminositySteps; // increase the firefly intensity / fade in
- yield return new WaitWhile(() => pointLight.intensity >= maxLuminosity); // wait for the maximum intensity
- yield return new WaitForSeconds(shineDuration); // wait 3 seconds
- pointLight.intensity -= luminositySteps;
- yield return new WaitWhile(() => pointLight.intensity <= maxLuminosity); // wait for the minimum intensity
- StartCoroutine(ChangeIntensity()); // do it again
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement