For some reason, the update function is only running once. Why does this happen?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightFlicker : MonoBehaviour
{
float timer;
float timetowait;
// Use this for initialization
void Start()
{
timer = 0;
timetowait = Random.Range(0.01f, 0.8f);
}
// Update is called once per frame
void Update()
{
Debug.Log("Updating");
timer += Time.deltaTime;
if(timer >= timetowait)
{
if (gameObject.activeInHierarchy == true)
{
gameObject.SetActive(false);
}
else
{
gameObject.SetActive(true);
}
timetowait = Random.Range(0.01f, 0.8f);
timer = 0;
}
}
}
The debug.log statement only fires 9 times. Edit: Also, the The timetowait changes, but the timer stays the same.