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.