Android back button with pause game issue

Hi, I have added Android back button event on my game, when I press android back button game will pause, then I press again game will resume. But, used this feature in Update function. If I hold back button, game will pause-resume-pause-resume so on. How can I control this? I think I used flag but how?

to check if the back button has been pushed in your update function, use

if( Input.GetKeyDown( KeyCode.Escape ) )
{
     HandleBackPressed();
}

This will be true only on the frame on which the back button is pushed. it won’t be true again until the user lets go of the back button and pushes it again. that way, holding it down won’t cause a repeat. This works for all keys, not just the back button

Ohh, I used GetKey, not GetKeyDown thanks your answer.

Just FYI - this is not a recommended behavior. According to Google design recommendations for Android TV (and will probably apply for all Androids), back button should navigate you back and be able to bring you to the home screen, not back and forth.

Just a thing to consider :wink:

Xb,Okay android back button is escape but volume button is what?