Created
November 5, 2024 23:21
-
-
Save andydbc/ece3097195bdca88429a2c8d28225c7d to your computer and use it in GitHub Desktop.
Randomly flicker a light intensity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
[RequireComponent(typeof(Light))] | |
public class Flicker : MonoBehaviour | |
{ | |
Light _light; | |
private float _intensity; | |
void Start() | |
{ | |
_light = GetComponent<Light>(); | |
_intensity = _light.intensity; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
var t = Mathf.PerlinNoise(Time.time * 2.0f, Time.time * 4.0f); | |
_light.intensity = t > 0.1f ? _intensity : 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment