1 Button Alternating Between 2 onClick Functions

I want a single button to carry out ONLY ONE of two onClick functions at a time. The timing will be determined by an OnTriggerEnter2D/OnTriggerExit2D script attached to the trigger of an orbiting game object constantly entering and exiting, at the top of its path, the trigger. I want the button to add a point(which is one of my onClick functions), but only if the game object is inside the trigger. If it’s outside the trigger, I want that same button to bring you to the Game Over Scene(the other one of my onClick functions). How can I enable and disable these onClick functions based off the collision detection so that it works smoothly? I appreciate the help!

Have the button call a function that calls one of two different functions depending on some bool value. Like this pseudo-ish code:

public bool isInTrigger;

private void DoThingWhenButtonPressed() //Called by button's onClick
{
        if(isInTrigger)
        {
                DoThing1(); //Add to score?
        }
        else
        {
                DoThing2(); //Game Over?
        }
}

Then just set the bool value on a script on the GameObject that has your Trigger. Maybe use OnTriggerEnter and set it to true and OnTriggerExit and set it to false. Hope this helps! :slight_smile: