• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sanks007 · Dec 04, 2013 at 01:06 PM · flickergui buttonsguilayout.window

GUI Layout flickering while exiting application

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sanks007 · Dec 14, 2013 at 04:32 AM 0
Share

From what I found is the back button is being called multiple times. I put a count variable inside if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Escape)) { visible=true; } and found that count is always >1 . So what can be done about this.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sanks007 · Jan 21, 2014 at 11:10 AM

When upgraded to unity 4.3.1 it is working fine. No flickering & nothing so it might be something with the unity not sure though.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cam Flickering This is A BUG ? 0 Answers

Plane / Decal Flashes With Player / Camera Movement 1 Answer

Avatars have flickering white dots 0 Answers

Use GUI buttons to move a character. 1 Answer

Light/Shadow Z-Fighting Styled Flickering while Camera is Moving Around 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges