Skip to content

Instantly share code, notes, and snippets.

@r2d2m
Forked from LotteMakesStuff/Flicker.cs
Created May 20, 2022 10:20
Show Gist options
  • Select an option

  • Save r2d2m/dba5359bb96f539d55272986d76820b3 to your computer and use it in GitHub Desktop.

Select an option

Save r2d2m/dba5359bb96f539d55272986d76820b3 to your computer and use it in GitHub Desktop.

Revisions

  1. @LotteMakesStuff LotteMakesStuff created this gist Jun 16, 2021.
    42 changes: 42 additions & 0 deletions Flicker.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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];
    }
    }