Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 ConanHorus · Jun 13, 2011 at 08:04 PM · guiglitchselection

GUI is too sensitive

Alright, this question has been bugging me for a while. It is really specific to my code so search as I have, I couldn't find anything helpful save a few articles about clicking on GUI elements.

So here is what's happening: I choose place a tower on the grid (tower selection is on a drop-down GUI at the top of the screen), then I choose the green-line "selector." I select the tower I just placed putting an orange arrow and a white radius circle around the tower. When I click on any of the GUI (even a box), the tower deselects. But when I debug, all the variables are as they should be. I have even commented out large blocks of code to find the troubled area to no avail.

I have posted the current build of the game here.

The code in question is attached to my main camera, and is located here. I am really bad at commenting code when I am the only one that will see it, so I will start commenting it right away and upload that version asap.

With those resources I ask my question: Why does the tower deselect? What am I doing wrong? Is it a glitch with Unity's code conversion? How can I get the effect I want?

In the mean-time, I will comment my code and continue reading other articles in the off chance that someone else has encountered this problem. Also, if you need more info, I am happy to offer anything that will help solve this problem.

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

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jun 13, 2011 at 08:35 PM

Just because you click on a gui button that doesn't make this code invalid:

 if (Input.GetMouseButtonDown(0))
     if (mouseOnScreen)
         isSelected = false;

You already check if the mouse is within the screen, but you should ignore the click as well when you're inside a GUI.

You can use the Rect.Contains function to test if the mouseposition is within the GUI.

This test should be done inside OnGUI. Event.current.mousePosition holds the mouse position in GUI coordinates (0,0 == top left):

 overGUI = Rect(Screen.width - 500, Screen.height - 94, 500, 94).Contains(Event.current.mousePosition);


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 ConanHorus · Jun 13, 2011 at 09:44 PM 0
Share

Bunny83,

Thank you for your help. It works very well! I was skeptical at first because my logical side told me that it would have the same effect as the code I had already written. Then I realized, that's exactly what I wanted.

Alright, well have fun all!

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Impossible: 2 toolbars show being clicked at the same time! 1 Answer

A 2D GUI in mid air, for oculus, tracking an object. 1 Answer

Selection box - drawing corner issue. 1 Answer

UI working fine in editor but glitched in standalone builds 1 Answer

Unexpected selection state in custom inspector? 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