I’m trying to create a script which would automatically activate and reactivate all GameObjects with the tag ‘Flare’ on them. ‘flareOnTime’ is for how long it is active and ‘flareOffTime’ is for how long it is inactive. I’m stuck right now and cannot figure out what is wrong with my code. I would reaaly appriciate any help.
Code:
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public float flareOnTime;
public float flareOffTime;
GameObject[] gos;
// Use this for initialization
void Start () {
GameObject[] gos = GameObject.FindGameObjectsWithTag("Flare");
StartCoroutine("BlinkFlare");
}
// Update is called once per frame
void Update () {
}
IEnumerator BlinkFlare() {
while (true) {
yield return new WaitForSeconds (flareOnTime);
foreach (GameObject go in gos){
go.SetActive(false);
}
yield return new WaitForSeconds (flareOffTime);
foreach (GameObject go in gos){
go.SetActive(true);
}
}
}
}