Open and Close Button

Hi, I’m extremely new to Unity and am testing a menu I created.

I require a window (game object) to appear when a button is pressed(mouse click), but also disappear when the button is pressed a second time.

Below is the code I’ve been trying to use.

I really appreciate any and all help.

var target : GameObject;
function start () {

   target.SetActive(false);
}
function OnMouseDown () {

   target.SetActive(true);
}

function OnMouseUp () {

   target.SetActive(false);
}

start() should be Start()
OnMouseUp/Down requires a collider be attached to the GameObject that this script is on (and that you click on that collider)

1 Like

Thanks a lot for the assistance!
Is there a way to make gameobject remain active after clicking, atm the object appears on mouse down, then disappears on mouse up?

Cheers

Remove the OnMouseUp() method.

1 Like

Thanks guys.

I used the OnMouseUp() to cause the gameObject to reappear if clicked a second time. How could I make that function?

Maintain the state in a boolean

bool active;

void OnMouseUp()
{
    active = !active;
    target.SetActive(active);
}

Where would I place the this part of the code?