Multiple (Android)back button detector in one scene problem

I have multiple button in my scene that I want to trigger when user press back button on Android but at different circumstances. This is a very common feature that most app have.

For example : if user open the shop(a panel), an on-screen button that close the shop will trigger, but when the shop panel isn’t opening then a on-screen button that load another scene will trigger.

This is my code

private Button butt;

    void Start () {
        butt=GetComponent<Button>();
    }

    // Update is called once per frame
    void Update () {
        if(Input.GetKeyUp (KeyCode.Escape))
            butt.onClick.Invoke ();
    }

The problem is when I press the back button all of the script get trigger. Anyone know a workaround? Like somehow get the lowest button in the hierarchy(aka the one that on top)?

Ps: In the example I could just add a simple If else statement but my scenes is pretty complicated and I don’t want to hard code everything.

This is a very confusing question - in the first sentence you say you want all the buttons to trigger and in the section after the code you say that’s the problem.

Could you try clarifying your question?

1 Like

Sorry for the confusion. I fixed the post