Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Kashrlyyk · Jun 21, 2012 at 01:04 PM · inputmousepositioncontains

Contains(Input.mousePosition) reacts to wrong rect

In my code I have 12 buttons. All with their own functionality and all work as intended. For six of them I added a "MouseOver" functionality and I now want to do that for the other six too.

But I am running in a weird problem.

Definition of the buttons:

  private Rect ButtonO1;
         private Rect ButtonO2;
         private Rect ButtonO3;
         private Rect ButtonU1;
         private Rect ButtonU2;
         private Rect ButtonU3;
         private Rect ButtonLO1;
         private Rect ButtonRO1;
     
     void Start () {
             ButtonO1 = new Rect(Screen.width/2+70,Screen.height/5-55,50,50);
             ButtonO2 = new Rect(Screen.width/2-25,Screen.height/5-55,50,50);
             ButtonO3 = new Rect(Screen.width/2-120,Screen.height/5-55,50,50);
             ButtonU1 = new Rect(Screen.width/2+70,Screen.height-90,50,50);
             ButtonU2 = new Rect(Screen.width/2-25,Screen.height-90,50,50);
             ButtonU3 = new Rect(Screen.width/2-120,Screen.height-90,50,50);
             
             ButtonLO1 = new Rect(Screen.width/2-200,Screen.height/5+25,50,50);
             ButtonRO1 = new Rect(Screen.width/2+150,Screen.height/5+25,50,50);
         }

In the Update function I have this

 void Update () {
         if         (ButtonO1.Contains(Input.mousePosition) || ButtonU1.Contains(Input.mousePosition)) {
             OnMouseOverO1();}        
         else if (ButtonO2.Contains(Input.mousePosition) || ButtonU2.Contains(Input.mousePosition)) {
             OnMouseOverO2();}        
         else if (ButtonO3.Contains(Input.mousePosition) || ButtonU3.Contains(Input.mousePosition)) {
             OnMouseOverO3();}
         else if (ButtonLO1.Contains(Input.mousePosition) || ButtonRO1.Contains(Input.mousePosition)) {
             Debug.Log("Button L1 oder R1");}
         else {
             OnMouseExit();}        
     }

The first six buttons work flawlessly. When I hover over them it does what it is supposed to do. If I hover over the ButtonLO1 or RO1 nothing happens. The Debug.Log command is only processed when I hover over two of the remaining four buttons. And I have no idea why!!! If I press the ButtonLO1 it works. So some part of the engine realizes I am hovering and clicking that button even so the Contains(Input.mousePosition) clearly doesn't.

Does anyone know why the engine confuses those buttons? Why does it nothing happen if I hover over ButtonLO1? Should I report a bug?

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 DaveA · Jun 21, 2012 at 02:13 PM 2
Share

I recall having to invert the screen 'y' coordinate at some point. You may need to add 'Screen.height-' in front of your 'y' components

avatar image Berenger · Jun 21, 2012 at 02:51 PM 1
Share

Sounds like an Y inverted allright.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kashrlyyk · Jun 22, 2012 at 10:08 AM

Thanks, that was exactly what I wanted to test today.

Is there any reason why the "Input.mousePosition" starts in the lower left corner and the position of "Rect" starts in the upper left corner? Why are they different?

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 Berenger · Jun 22, 2012 at 05:17 PM 0
Share

I guess it's related to the functions Camera.ScreenToWorldPoint and co.

avatar image Loius · Jun 22, 2012 at 08:14 PM 0
Share

I have asked this question for the past twenty years. No two coordinate systems are the same and I always bash my head against a wall for a few $$anonymous$$utes before I remember mouse is down and screen is up or Y is up here and Z is up there (and I think X was up once...)

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI label dimensions bug 2 Answers

How do I use controller knob input like mouse position? (New Input System) 1 Answer

Input.mousePosition only detects motion outside of window if I move really slow. 1 Answer

How do I rotate an object using Vector2 inputs? (New Input System) 1 Answer

Input.mousePosition Dead Zone - See gameplay 0 Answers


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