• 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 HotPhone · May 29, 2014 at 10:25 PM · guiinputmousepositionrectcontains

GUI label dimensions bug

Probably I am overworked but that bug that I'm having is very wierd.

I draw stuff in rectangles:

         void OnGUI ()
         {          
                 GUI.Label (headlineRect, "HEADLINERECT", headlineStyle);      
                 GUI.Label (buttonRect, "BUTTONRECT", headlineStyle);
         }

         void Update ()
         {  
                 if (buttonRect.Contains (Input.mousePosition) && Input.GetMouseButtonDown (0)) {            
                         doStuff()...        
                 }
         }

Seems legit to me. The Rectangles are created in Start(). Doesnt even matter because I can see the two labels in the game.

Now when I click the "BUTTONRECT" text in game nothing happens. But when I click the "HEADLINERECT" text, doStuff() happens.

I am using version 4.3.4 I tried to restart unity. When I change the buttonrect in update() to headlineRect it works like it should.

Comment
Add comment · Show 6
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 meat5000 ♦ · May 29, 2014 at 10:25 PM 1
Share

Sounds like you've switched your Rect dimensions in their declaration, or something to that effect.

Or you are placing them next to each other and miscalculating the dimensions somehow having one twice the height or width of the other and overlapping it.

avatar image JayOhhh · May 30, 2014 at 12:14 AM 0
Share

What are your two rect dimensions?

avatar image Kiwasi · May 30, 2014 at 12:21 AM 1
Share

Any reason why you are using GUI.Label ins$$anonymous$$d of GUI.Button?

Seems strange to write your own code when unity will carry out the functionality for you.

avatar image rutter · May 30, 2014 at 12:21 AM 0
Share

A reproducible example would be amazingly helpful; without one, I have to assume there's a problem in some of the code you're not showing.

avatar image Eric5h5 · May 30, 2014 at 01:06 AM 0
Share

I would normally agree about using GUI.Button, but I assume the usage of $$anonymous$$ouseButtonDown like this is intentional, since the behavior is different (GUI.Button activates when the button is released).

Show more comments

2 Replies

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

Answer by Eric5h5 · May 30, 2014 at 01:03 AM

You shouldn't use Input.mousePosition for OnGUI code, since it uses a different coordinate system. Or mix Update with OnGUI for that matter. Use Event.current.mousePosition (and EventType.MouseDown) put all the input code in OnGUI.

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

Answer by HotPhone · Jun 08, 2014 at 03:11 PM

I solved this with an own RectContains function. the y axis is in two different directions.

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

25 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

Related Questions

Input.mouse position on GUI Textures 2 Answers

Mouse moves over GUI 1 Answer

Need help understanding GUI and Rect.Contains interaction 0 Answers

strange Rect behavior on Y axis 1 Answer

Contains(Input.mousePosition) reacts to wrong rect 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