Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. private Light pointLight; // The light component of the firefly
  2.  
  3. private float minLuminosity = 0; // min intensity
  4. private float maxLuminosity = 1; // max intensity
  5.  
  6. private float luminositySteps = 0.005f; // factor when increasing / decreasing
  7.  
  8. private float shineDuration = 3; // wait 3 seconds when faded in
  9.  
  10. private void Start()
  11. {
  12. pointLight = GetComponent<Light>();
  13. pointLight.intensity = Random.Range(minLuminosity, maxLuminosity); // start with a random intensity
  14. StartCoroutine(ChangeIntensity()); // start the process
  15. }
  16.  
  17. private IEnumerator ChangeIntensity()
  18. {
  19. pointLight.intensity += luminositySteps; // increase the firefly intensity / fade in
  20. yield return new WaitWhile(() => pointLight.intensity >= maxLuminosity); // wait for the maximum intensity
  21.  
  22. yield return new WaitForSeconds(shineDuration); // wait 3 seconds
  23.  
  24. pointLight.intensity -= luminositySteps;
  25. yield return new WaitWhile(() => pointLight.intensity <= maxLuminosity); // wait for the minimum intensity
  26.  
  27. StartCoroutine(ChangeIntensity()); // do it again
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement