Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class LightFlicker : MonoBehaviour
- {
- private Light light;
- [Tooltip(tooltip: "The total amount of time in where light turns off and on.")]
- public float periodTime = 5f;
- [Tooltip(tooltip: "The percent of time elapsed before light turns off.")]
- [Range(min: 0, max: 1)]
- public float dutyTime = 0.5f;
- [Tooltip(tooltip: "The intensity of the light.")]
- public float intensity = 1f;
- private float currentPeriodTime;
- // Start is called before the first frame update
- void Start()
- {
- currentPeriodTime = periodTime;
- this.light = GetComponent<Light>();
- light.enabled = true;
- }
- // Update is called once per frame
- void Update()
- {
- Debug.Log(currentPeriodTime);
- if(currentPeriodTime > 0)
- {
- currentPeriodTime -= Time.deltaTime;
- } else
- {
- currentPeriodTime = periodTime;
- light.enabled = true;
- }
- if (currentPeriodTime < periodTime * dutyTime) light.enabled = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement