I have 2 functions for turning off fires/lights in my scene. The lights off function is working properly. But the lights on is not working at all. I watch the inspector window and it does not show that it is populating the array at all. I am using tags on the items that I want to turn on and off. I am still fairly new to Unity scripting so this may be something simple to fix. I am using GUI buttons to toggle the functions and that is working properly. Any assistance would be appreciated.
public GameObject[] lights;
public GameObject[] fires;
public void lightsOff()
{
lights = GameObject.FindGameObjectsWithTag("light");
foreach (GameObject light in lights)
{
light.SetActive(false);
}
fires = GameObject.FindGameObjectsWithTag("fire");
foreach (GameObject fire in fires)
{
fire.SetActive(false);
}
}
public void lightsOn()
{
lights = GameObject.FindGameObjectsWithTag("light");
foreach (GameObject light in lights)
{
light.SetActive(true);
}
fires = GameObject.FindGameObjectsWithTag("fire");
foreach (GameObject fire in fires)
{
fire.SetActive(true);
}
}
i don't use C# but maybe you can translate this into C#, or something close to it. basically when you use this, it's the same as a true and false. lets say this: function Update () { // tested if(Input.GetKeyDown(KeyCode.Tab)){ for(var a1 in lights){ a1.active = !a1.active; } } } then again, this might not even be what you were asking. hope this was some kind of help.
– ownerfate