-
-
Save gu3st/9e6d99fdf18ccd988e5c04465f3ac14b to your computer and use it in GitHub Desktop.
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; | |
public class QuakeLightFlicker : MonoBehaviour | |
{ | |
public float maxLightIntensity = 2f; | |
public string flickerString = "mmamammmmammamamaaamammma"; | |
public Light light; | |
int index = 0; | |
float defaultInt = 1; | |
public GameObject optionalToggleObject; | |
char[] chars; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
light = GetComponent<Light>(); | |
defaultInt = light.intensity; | |
StartCoroutine(Flicker()); | |
chars = flickerString.ToCharArray(); | |
} | |
IEnumerator Flicker() | |
{ | |
while (true) | |
{ | |
yield return new WaitForSeconds(0.1f); | |
if (light) | |
{ | |
int charIndex = (int)chars[index] % 32; | |
float value = ((float)charIndex / 32f) * maxLightIntensity; | |
light.intensity = value; | |
if (flickerString.Substring(index, 1) == "a") | |
{ | |
if (optionalToggleObject) | |
optionalToggleObject.SetActive(false); | |
} | |
else | |
{ | |
//light.intensity = 0.1f; | |
if (optionalToggleObject) | |
optionalToggleObject.SetActive(true); | |
} | |
index = (index + 1) % flickerString.Length; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment