Skip to content

Instantly share code, notes, and snippets.

@andydbc
Created November 5, 2024 23:21
Show Gist options
  • Save andydbc/ece3097195bdca88429a2c8d28225c7d to your computer and use it in GitHub Desktop.
Save andydbc/ece3097195bdca88429a2c8d28225c7d to your computer and use it in GitHub Desktop.
Randomly flicker a light intensity
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