41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
public class LightFlickerController : MonoBehaviour
|
|
{
|
|
public float minFlickerSpeed;
|
|
public float maxFlickerSpeed;
|
|
public float minIntensity;
|
|
public float maxIntensity;
|
|
public Light2D light;
|
|
private float flickerTimer;
|
|
private float nextFlickerTime;
|
|
|
|
private void Start()
|
|
{
|
|
flickerTimer = 0;
|
|
light.enabled = true; // Keep the light enabled to control intensity
|
|
SetNextFlicker();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
flickerTimer += Time.deltaTime;
|
|
if (flickerTimer >= nextFlickerTime)
|
|
{
|
|
light.intensity = Random.Range(minIntensity, maxIntensity); // Randomize intensity
|
|
SetNextFlicker();
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
light.enabled = false;
|
|
}
|
|
|
|
private void SetNextFlicker()
|
|
{
|
|
flickerTimer = 0;
|
|
nextFlickerTime = Random.Range(minFlickerSpeed, maxFlickerSpeed); // Randomize time until next flicker
|
|
}
|
|
} |