UnityGameProjectsCode / AbandondedGame / Flicker.cs
Flicker.cs
Raw
using Aura2API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Flicker : MonoBehaviour
{
    public bool flicker;
    private float timeSinceLastLightChange;
    private float randomPause;
    private Light targetLight;
    private AudioSource aSource;
    private bool randomPauseSet;

    private void Awake()
    {
        targetLight = GetComponent<Light>();
        aSource = GetComponent<AudioSource>();
    }

    private void Update()
    {
        if(flicker)
        {
            if(!randomPauseSet)
            {
                randomPause = Random.Range(0.0f, 2.0f);
                randomPauseSet = true;
            }

            timeSinceLastLightChange += Time.deltaTime;

            if (timeSinceLastLightChange >= randomPause)
            {
                targetLight.enabled = !targetLight.enabled;
                aSource.Play();
                randomPauseSet = false;
                timeSinceLastLightChange = 0.0f;
            }
        }
    }
}