When user press back button for exit, I am showing a dialog made of GUI components. When i press yes button for exit the layout flickers for sometime and then the application exit. Here is the script .
public class MainScreenGUIScript : MonoBehaviour
{
public bool visible;
public GUISkin customSkin;
float screenWidth;
float screenHeight;
float dialogStartX;
float dialogStartY;
float dialogWidth;
float dialogHeight;
float DialoglabelX;
float DialoglabelY;
float DialogTitlelabelX;
float DialogTitlelabelY;
float DialoglabelWidth;
float DialoglabelHeight;
float DialogYesButtonX;
float DialogYesButtonY;
float DialogNoButtonX;
float DialogNoButtonY;
float DialogButtonWidth;
float DialogButtonHeight;
public GUIStyle boxBackgroundStyle;
public GUIStyle yesButtonStyle;
public GUIStyle noButtonStyle;
public GUIStyle titleLabelStyle;
public GUIStyle fbStyle;
public GUIStyle settingStyle;
float buttonWidth;
float buttonHeight;
float buttonY;
float othersX;
float backX;
void Start ()
{
visible=false;
}
// Update is called once per frame
void OnGUI()
{
GUI.skin = customSkin;
screenWidth=Screen.width;
screenHeight=Screen.height;
dialogStartX=(float) (screenWidth*0.275);
dialogStartY=(float) (screenHeight*0.35);
dialogWidth=(float) (screenWidth*0.5);
dialogHeight=(float) (screenHeight*0.28);
DialoglabelWidth=(float) (screenWidth*0.3);
DialoglabelHeight=(float) (screenHeight*0.1);
DialoglabelX=(float) (screenWidth*0.415);
DialoglabelY=(float) (screenHeight*0.45);
DialogTitlelabelX=(float) (screenWidth*0.4);
DialogTitlelabelY=(float) (screenHeight*0.36);
DialogYesButtonX=(float) (screenWidth*0.36);
DialogYesButtonY=(float) (screenHeight*0.54);
DialogNoButtonX=(float) (screenWidth*0.55);
DialogNoButtonY=(float) (screenHeight*0.54);
DialogButtonWidth=(float) (screenWidth*0.15);
DialogButtonHeight=(float) (screenHeight*0.08);
buttonWidth=(float) (screenWidth*0.06);
buttonHeight=(float) (screenHeight*0.08);
othersX=(float) (screenWidth*0.9);
backX=(float) (screenWidth*0.01);
buttonY=(float) (screenHeight*0.89);
if(GUI.Button(new Rect(othersX,buttonY,buttonWidth,buttonHeight),"",fbStyle))
{
if(!visible)
{
Application.OpenURL ("");
}
}
if(GUI.Button(new Rect(backX,buttonY,buttonWidth,buttonHeight),"",settingStyle))
{
if(!visible)
{
Application.LoadLevel(3);
}
}
if(visible)
{
GUI.Box(new Rect(0,0,Screen.width,Screen.height),"");
GUI.Box(new Rect(dialogStartX,dialogStartY,dialogWidth,dialogHeight),"",boxBackgroundStyle);
GUI.Label(new Rect(DialogTitlelabelX,DialogTitlelabelY,DialoglabelWidth,DialoglabelHeight),"Quit",titleLabelStyle);
GUI.Label(new Rect(DialoglabelX,DialoglabelY,DialoglabelWidth,DialoglabelHeight),"Do You Want To Quit ?");
if(GUI.Button(new Rect(DialogYesButtonX,DialogYesButtonY,DialogButtonWidth,DialogButtonHeight),"",yesButtonStyle))
{
visible=false;
applicationExit();
}
if(GUI.Button(new Rect(DialogNoButtonX,DialogNoButtonY,DialogButtonWidth,DialogButtonHeight),"",noButtonStyle))
{
visible=false;
}
}
if (Input.GetKey(KeyCode.Escape))
{
visible=true;
}
}
void applicationExit()
{
Application.Quit();
}
}
Initially there are two GUI.Button which are visible. When user press back key(Android) I change the value of visible to true so that dialog appears . When user clicks on Yes Button I set value of visible to false and then call Application.Quit() it flickers and then application exit. What could be the reason.