• 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 phxvyper · Jul 08, 2014 at 03:29 AM · c#guidebugonguiguilayout

GUILayout not working for me C#

Hello, I've coded the following OnGUI function. My Debug.Log methods are logging properly, showing that the code is getting reached. However, my GUI isn't showing up! Why is this?

 void OnGUI() {
     if (ShowRestartWindow) {
         #region Restart Window
 
         if (Event.current.type == EventType.Layout) {
             Debug.Log("layout");
             GUILayout.BeginArea(new Rect(10f, 10f, 100f, 100));
             {
                 Debug.Log("RestartWindow shown");
                 PlayerController pc = GetComponent<PlayerController>();
                 int playerScore = pc.playerDisplayedScore;
                 int highScore = pc.HighestPlayerScore;
 
                 GUILayout.Label("Your Score: " + playerScore.ToString());
                 GUILayout.Label("High Score: " + highScore.ToString());
 
                 if (GUILayout.Button("Play Again?")) {
                     //Time.timeScale = 1;
                     Application.LoadLevel("main");
                 }
 
             }
             GUILayout.EndArea();
         }
 
         #endregion
     }
 }

Comment
Add comment · Show 2
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 Kiwasi · Jul 08, 2014 at 03:35 AM 0
Share

Try drop your rect back to (0,0,100,100).

Any luck? Worked for the last person who had this problem on UA

avatar image phxvyper · Jul 11, 2014 at 09:32 AM 0
Share

@Bored$$anonymous$$ormon i tried it, and it failed. :/

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Ngoc Ngo · Jul 08, 2014 at 03:54 AM

I think it would work without the guard on line 5.

Comment
Add comment · Show 3 · 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
avatar image phxvyper · Jul 08, 2014 at 04:39 AM 0
Share

This should be a comment, not an answer.

Also: It didn't work due to GUI $$anonymous$$anipulation rules, that's why they're there in the first place.

avatar image Bunny83 · Jul 08, 2014 at 06:02 AM 4
Share

@phxvyper: No, this should be an answer since it is correct. What "GUI $$anonymous$$anipulation rules" are you talking about? OnGUI is called to process events. There are many different type of events. The layout event is only for gathering information about the controls you want to draw. The controls itself are drawn when the repaint event is issued. Input is processed when a mouse keyboard event is issued. Since you filter out all events but layout the whole system doesn't work.

You might want to read my crash course about the GUI system.

avatar image phxvyper · Jul 11, 2014 at 09:31 AM 0
Share

@Bunny83 It isn't correct for my situation. I was manipulating a variable with affected the state of the GUI (somehow), and it caused an error to pop up. I googled the error and another person who had the issue posted it on unity answers. Someone replied with that if statement, the error is now gone because of it.

I used the repaint event in the if statement and it still showed the error.

Edit: I changed the GUI around a bit and removed that if statement. The changes i made didn't work until the if statement was removed. I'm unsure what exactly was creating that error. ~ so now it works

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using treeview OnGUI with GUIlayout 0 Answers

Using GUI and GUILayout at the same time 1 Answer

Multiple Cars not working 1 Answer

GUI Depth Sorting 1 Answer

Method is called, but GUI doesn't show up 1 Answer


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