I need a way to check all scripts if boolean is true and then a way in this script to see in the if statement of the current light the character is standing next to has the boolean true to activate and only then should the Instantiate function be triggered.
private bool Once = true;
public Transform Spawnpoint1;
public Transform Spawnpoint2;
public GameObject Prefab1;
public GameObject Prefab2;
//Something like this, but I don't know where to go after that
GameObject[] Lights = GameObject.FindGameObjectsWithTag("lightSwitch");
//foreach(GameObject Light in Lights)
void OnTriggerEnter2D(Collider2D collision)
{
if (Once == true)
{
Debug.Log("It's true");
if (LightOnOff.isON == true) // It needs to check this constantly
{
Debug.Log(" It's Lit");
Instantiate(Prefab1, Spawnpoint1.position, Spawnpoint1.rotation);
Instantiate(Prefab2, Spawnpoint2.position, Spawnpoint2.rotation);
Once = false;
}
}
}
here is the Light script as well
public static bool isON;
public void lightOn()
{
this.GetComponent<Light>().enabled = true;
isON = true;
}