2

how can I handle back button single click , long click to pause game , if pressed again destroy game

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156

1 Answers1

2

I think the back button maps to mouse button 1 so you should be able to pick it up with:

Input.GetMouseButtonDown (1);

To detect double clicks or long clicks you would measure the time between each click or how long the button has been pressed, respectively. I have never tried this but it could be something along the lines of setting up a variable to hold the time interval and checking if the second click happens within that time.

-EDIT- I just found another discussion about this here with some examples which should help, e.g.

if(Input.GetMouseButtonDown(0))
{
 _buttonDownPhaseStart = Time.time;    
}

if (_doubleClickPhaseStart > -1 && (Time.time - _doubleClickPhaseStart) > 0.2f)
{
     Debug.Log ("single click");
     _doubleClickPhaseStart = -1;
}

if( Input.GetMouseButtonUp(0) )        
{
      if(Time.time - _buttonDownPhaseStart > 1.0f)
 {
     Debug.Log ("long click");
     _doubleClickPhaseStart = -1;
 }
 else
 {
     if (Time.time - _doubleClickPhaseStart < 0.2f)
      {
           Debug.Log ("double click");
           _doubleClickPhaseStart = -1;
      }
      else
      {
         _doubleClickPhaseStart = Time.time;
      }    
 }
}
Robert
  • 5,278
  • 43
  • 65
  • 115