I wanted it so when you interact with a lightswitch it would set a point light active, however even when I assign the light I still get the error.
public class InteractionScript : MonoBehaviour
{
private bool doorCollision;
private bool radioCollision;
private bool sinkCollision;
private bool slipperCollision;
private bool lightCollision;
private bool openDoor = false;
private bool lightIsOn;
private bool slipperIsOn;
private bool radioIsOff1;
private bool radioIsOff2;
private bool waterWasDrank;
private Collider collider1;
public GameObject cup;
public GameObject slipper;
public GameObject hallwayLight; //This is the light that should become active
public Text hallwayTask;
public Text slipperTask;
public Text waterTask;
// Update is called once per frame
void Update()
{
if (doorCollision && Input.GetKeyDown("e"))
{
collider1.gameObject.transform.Rotate(0f, 180f, 0f);
openDoor = true;
}
if (lightCollision && Input.GetKeyDown("e")) //The statement that should activate the light
{
hallwayLight.SetActive(false);
lightIsOn = true;
}
if (slipperCollision && lightIsOn && Input.GetKeyDown("e"))
{
slipper.SetActive(false);
slipperIsOn = true;
}
if (radioCollision && slipperIsOn && Input.GetKeyDown("e"))
{
radioIsOff1 = true;
Debug.Log("Radio is now off");
}
if (sinkCollision && radioIsOff1 && Input.GetKeyDown("e"))
{
cup.SetActive(true);
waterWasDrank = true;
}
if (radioIsOff1)
{
slipperIsOn = false;
radioIsOff2 = true;
}
}
}
I know the interaction works because when I interact with the sink the cup becomes active fine, so I have absolutely no clue what the problem is. I wrote a debug.log statement for when I interacted with the light to make sure that the interaction wasn’t the problem, and it worked fine. And I also tried switching the light for other gameobjects like cubes and whatnot, but that did not work either. I tried accessing the light by writing
hallwaylight = gameobject.findobjectwithtag("light")
but that didnt work either Any help would mean the world to me since this project has been smooth sailing until this problem . Thank you!
