Click button to open pop up, click SAME button to close

Hi simple function I am looking for, yet unity just doesn’t seem to support it at all via the on click gui

Have a button, when I click it, a popup shows. Simple enough used onclick with setactive bool.
Now, where I really don’t understand why this doesn’t exist is to be able to set it that when I click it again, the popup will close. I have tried putting another set active below that and set that to false, but that doesn’t work.

If I add an event trigger, it has the option for on pointerenter and pointerexit as well as mouseup and mousedown. Now why is there no onclick and on click “again” functionality? I want this for mobile so I can’t make use of pointers or mouse clicks as those don’t exist in mobile


You want to toggle the gameobject between active and inactive right? You can toggle a boolean value between true and false by using value = !value. So to toggle whether or not something is active…


If activeInHierarchy is true then !activeInHierarchy return false. If it’s false then !activeInHierarchy returns true. This has the effect of toggling the active value between true and false, based on its current value. Or you might want to use activeSelf instead of activeInHierarchy.

So you can just call that in the button’s OnClick event to toggle the state.

Now, if the toggling script is a component on the object you’re toggling, once you set it to inactive the script will no longer run since scripts don’t run on inactive objects. The script needs to live on an object that isn’t inactivated, such as the button itself.

I don’t see the problem. You just use a bool to get what you want. If the bool is true get the popup. When it is clicked again, set the bool to false. I guess you are also using the unityEngine.UI system

ool start stage, if the popup is closed set this to true else false.

bool X = false; 

public void click(){
if(X == true){
X = false;
if(X ==false){
//close it
X = true;

public GameObject MultiViewerMenu;

public void OpenMultiViewerMenu()
if(MultiViewerMenu!= null)

        bool isActive = MultiViewerMenu.activeSelf;

I am using this code ,its clearly popping the panel but if i click it again its flickering and not responding.

Here you go! When you press a button a popup appears, then when you press the same button the same popup disappear

private bool clickedOnce = false;

public void PopUpPanel()
		if (!clickedOnce ) 
			clickedOnce = true;
			clickedOnce = false;