SHARE
TWEET

Untitled

a guest Sep 12th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class LightFlicker : MonoBehaviour
  4. {
  5.     private Light light;
  6.     [Tooltip(tooltip: "The total amount of time in where light turns off and on.")]
  7.     public float periodTime = 5f;
  8.     [Tooltip(tooltip: "The percent of time elapsed before light turns off.")]
  9.     [Range(min: 0, max: 1)]
  10.     public float dutyTime = 0.5f;
  11.     [Tooltip(tooltip: "The intensity of the light.")]
  12.     public float intensity = 1f;
  13.     private float currentPeriodTime;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         currentPeriodTime = periodTime;
  18.         this.light = GetComponent<Light>();
  19.         light.enabled = true;
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.         Debug.Log(currentPeriodTime);
  26.         if(currentPeriodTime > 0)
  27.         {
  28.             currentPeriodTime -= Time.deltaTime;
  29.         } else
  30.         {
  31.             currentPeriodTime = periodTime;
  32.             light.enabled = true;
  33.         }
  34.         if (currentPeriodTime < periodTime * dutyTime) light.enabled = false;
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top