Skip to content

Instantly share code, notes, and snippets.

@LotteMakesStuff
Created June 16, 2021 04:49
Show Gist options
  • Select an option

  • Save LotteMakesStuff/9612c5201d0308f86552f0600ac74802 to your computer and use it in GitHub Desktop.

Select an option

Save LotteMakesStuff/9612c5201d0308f86552f0600ac74802 to your computer and use it in GitHub Desktop.
Quake/Halflife style light flicker
using UnityEngine;
public class Flicker : MonoBehaviour
{
public string LightStyle = "mmamammmmammamamaaamammma";
private Light light;
public float loopTime = 2f;
[SerializeField]
private int currentIndex = 0;
private float lightTimer;
void Start()
{
light = GetComponent<Light>();
}
void Update()
{
char c = GetNextChar();
int val = c - 'a';
float intensity = (val / 25f)*2;
light.intensity = intensity;
}
private char GetNextChar()
{
lightTimer += Time.deltaTime;
var step = loopTime / LightStyle.Length;
if (step < lightTimer)
{
lightTimer -= step;
currentIndex++;
if (currentIndex >= LightStyle.Length)
currentIndex = 0;
}
return LightStyle[currentIndex];
}
}
@rpomykala

rpomykala commented Jun 16, 2021 •

Copy link
Copy Markdown

Very cool, thank you Lotte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment