• 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 /
This question was closed Sep 01, 2017 at 08:30 PM by Olinus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Olinus · Aug 31, 2017 at 06:53 PM · editor-scriptingeditorwindoweditorguieditor extensioneditorscript

Dynamic content in custom EditorWindow

Hi,

I am beginner to the EditorWindow scripting and am in need of support from you guys.

I would like to create a custom EditorWindow with my own dynamic content (just like a list).

I thought it would be simple to make but the following code is not working. Can you help please ?

 public void OnGUI() {
         if (GUILayout.Button("Press me !")) {
             GUILayout.Label("Hello !!!");
             Debug.Log("Call from OnGUI");
         }
     }

I get the message in the Debug.Log() but the label does not show.

I've added the Repaint() to the Update() method and still nothing. When I make the code static i.e. take out the label from the if() the it shows properly ... but this is not what I want to achieve.

Any guides would be helpfull.

Thanks

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by FortisVenaliter · Aug 31, 2017 at 09:07 PM

This is because Button() only returns true on the frame it's pressed. So, your label would only draw for 1/60th of a second.

You need to store a separate boolean and have the button toggle it, then check that boolean for whether or not to draw the label.

Comment
Add comment · Show 1 · 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 Olinus · Aug 31, 2017 at 09:23 PM 0
Share

Works ! Thanks !

 public void OnGUI() {
         if (GUILayout.Button("Press me !")) pressed = true;
 
         if (pressed) { 
             GUILayout.Label("Hello !!!");
             Debug.Log("Call from OnGUI");
         }
     }

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Is there a way to get all editable fields of a component in a script? 2 Answers

Better Unity Event UI 0 Answers

Editor GUI Foldout header style customization 0 Answers

Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer

Drag a non standard unity asset on a custom editor slot 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges