• 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
1
Question by Superboonie88 · Sep 03, 2012 at 09:50 PM · guibuttonevent-handling

Why is checking button click in Unity done this way?

I find the Unity way of writing the GUILayout.Button in onGUI to check for button click to contract the way I am used to seeing UI code, in which you instantiate a UI object and set up a click event handler for it. What's the reasoning behind doing it this way (from a framework creator's viewpoint)?

 function OnGUI {
     if (GUILayout.Button("Play")) {
         // button clicked  
     }
 }
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 Kiloblargh · Sep 03, 2012 at 10:23 PM 0
Share

I think this site is more for "how" questions than "why" questions. But I also think OnGUI is the event handler, and it's already been set up, internally. Right? So there you go.

avatar image Kronusdark · Sep 03, 2012 at 11:49 PM 0
Share

I would assume its faster to check for the buttons that you are interested in as needed, rather than scanning all input and firing individual methods, but I could be wrong.

1 Reply

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

Answer by Eric5h5 · Sep 03, 2012 at 10:47 PM

OnGUI is immediate mode. If you want something else, use GUITextures (which can use the OnMouseDown function), or wait for the new GUI system in Unity 4.something.

Comment
Add comment · Show 2 · 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 Lukas_GMC · Sep 05, 2012 at 07:07 PM 0
Share

When is 4.0 coming?

avatar image Eric5h5 · Sep 05, 2012 at 07:48 PM 0
Share

When it's done, but it won't have the new GUI system.

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

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

11 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

Related Questions

Android Button Screen 1 Answer

GUI Button Enable/Disable 1 Answer

Screenshot certain layers so it doesn't show GUI Button on the image?? 0 Answers

GUI.Button click trigger game object 1 Answer

Gathering GameObjects and then creating a button for each GameObject?? 2 Answers

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