Unity3D Quit Android Game with user prompt

android, unity-game-engine

Solution

you can do it with unity's gui attach this to a game object and it should do that you should make a GUI skin and play around with the components, you can add and tweak the components to your specifications

#pragma strict
var count : int = 0;
var skin : GUISkin;
function Update () {
if (Input.GetKeyDown(KeyCode.Escape)) { 
    Time.timeScale = 0;
    count = 1;
            }
}
function OnApplicationPause(){
Time.timeScale = 0;
count = 1;

}

function OnGUI(){
if(count == 1){
GUI.skin = skin;


   GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
   GUI.Label(new Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6), "Are you sure you want to exit the game?");
if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
          {

         Application.Quit();

          }
          if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
          {
          count = 0;
          Time.timeScale = 1;
}}}

Problem

Hi I have a code that quits the game on backspace key on Unity3D, But I want to give the user a YES/NO Question that he really wants to quit or not ? Just like this : Is there anyway to do this in Unity3D ? Thanks in advance

Original source