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
//b
ool start stage, if the popup is closed set this to true else false.
bool X = false;
public void click(){
if(X == true){
//popup
X = false;
}
if(X ==false){
//close it
X = true;
}