PolygonLightFade.cs 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace PolygonArsenal
  4. {
  5. public class PolygonLightFade : MonoBehaviour
  6. {
  7. [Header("Seconds to dim the light")]
  8. public float life = 0.2f;
  9. public bool killAfterLife = true;
  10. private Light li;
  11. private float initIntensity;
  12. // Use this for initialization
  13. void Start()
  14. {
  15. if (gameObject.GetComponent<Light>())
  16. {
  17. li = gameObject.GetComponent<Light>();
  18. initIntensity = li.intensity;
  19. }
  20. else
  21. print("No light object found on " + gameObject.name);
  22. }
  23. // Update is called once per frame
  24. void Update()
  25. {
  26. if (gameObject.GetComponent<Light>())
  27. {
  28. li.intensity -= initIntensity * (Time.deltaTime / life);
  29. if (killAfterLife && li.intensity <= 0)
  30. Destroy(gameObject);
  31. }
  32. }
  33. }
  34. }