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 lukewilliams · Feb 24, 2014 at 01:43 PM · javascriptrect

Why doesn't Unity like my rectangles?

So I'm having some trouble with one of my rectangles. Here are the rectangles I'm using:

 var leftHandRect = Rect.MinMaxRect(0.22*Screen.width,(2/3)*Screen.height,0.4*Screen.width,Screen.height);
     var rightHandRect = Rect.MinMaxRect((2/3)*Screen.width,(2/3)*Screen.height,0.83*Screen.width-1,Screen.height);
     var bothHandRect = Rect.MinMaxRect(0.4*Screen.width,(2/3)*Screen.height,(2/3)*Screen.width,Screen.height);

The code works fine for leftHandRect, I haven't added functionality to bothHandRect yet so I can't test that, but it doesn't like rightHandRect at all. When I first tried it out, I had slightly different rectangles, and the left one was working fine, but the right one did nothing. (When I say working, I mean using leftHandRect.Contains to check a touch event and then do something. I know the 'do something' code works, cos it was working earlier and works with the left hand rect, but now that the right hand rect is the way it is, it takes over and picks up every touch event no matter where it is on the screen, and the bounds of the rect are clearly not the whole screen. Any ideas? Cheers

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 lukewilliams · Feb 24, 2014 at 12:53 PM 0
Share

Ok so I half figured it out. Realised that my approximated maths probably meant that the rectangles were going below the bottom of the screen. Fixed that, and well only one of the rectangles got fixed. Still got a problem with one. There must be a better solution.

avatar image lukewilliams · Feb 24, 2014 at 01:37 PM 0
Share

the above comment makes no sense now that I've edited the question. I've been having quite a bit of trouble with these rectangles!

1 Reply

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

Answer by lukewilliams · Feb 24, 2014 at 02:03 PM

Ok so I figured it out.

2 things to note:

  • Unity doesn't like fractions of Screen.width and Screen.height. Perhaps a bug, or not rounding pixels correctly.

  • And secondly, there's an error in the reference for Rect. At least for Rect.MinMaxRect, xMin and yMin are actually the bottom left hand corner, not the top. Hope this helps some people! And hopefully someone from Unity will see this and update the reference! (I don't know how to contact them directly).

Comment
Add comment · Show 3 · 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 KiraSensei · Feb 24, 2014 at 02:04 PM 0
Share

Unity likes fractions of Screen.width and Screen.height of course. You can't place anything if not.

avatar image lukewilliams · Feb 24, 2014 at 02:11 PM 1
Share

hmm well I tried using fractions of Screen.width and Screen.height and it didn't work for me, but as soon as i changed stuff like (2/3) to 0.66 it worked. $$anonymous$$aybe its a bit buggy. Who knows. Glad it works for you, it sure annoyed me for a long time.

avatar image rakkarage · May 01, 2014 at 03:36 AM 0
Share

i think that is because you would need to say 2f/3f to get a fraction else int

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

21 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

Related Questions

What could be causing this problem reading from a Rect into a Vector2? 3 Answers

Debug.draw rect 2 Answers

Rect.Contains doesn't appear to be working with Input.GetTouch.position 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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