Toggle Active GameObject State

Hey guys. I’m trying to work on a script for a sink that allows the player to toggle a prefab that is a child of the sink object (the water) I’m trying to make it so that when the player clicks the mouse, it toggles the water to simulate turning the sink on and off. However, I’m not quite sure how to do this. I tried setting it up but it won’t work. Any help?

var AudioFile : AudioClip;
var object : GameObject;
var inRange : boolean;
var toggleBool : boolean;

function OnTriggerEnter() {
	inRange = true;
}

function OnTriggerExit() {
	inRange = false;
}

function OnMouseDown() {
	if(inRange == true)
	{
		object.SetActive(toggleBool);
		Switch();
		Debug.Log("toggle");
	}
}

function Switch() {
	if(toggleBool == true)
	{
		toggleBool = false;
		Debug.Log("set false");
	}
	if(toggleBool == false)
	{
		toggleBool = true;
		Debug.Log("set true");
	}
}

You’re setting the boolean to false, then checking if it’s false (which it is because you just made it false), and setting back to true. However you don’t need to do any of that, you can just set the state to the opposite value.

function OnMouseDown() {
     if (inRange) {
         object.SetActive (!object.activeInHierarchy);
         Debug.Log ("toggle");
     }
 }