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
0
Question by Extrakun · Jun 11, 2011 at 07:01 AM · guiscreen-coordinates

How do I get the upper-right corner screen position of a model?

I have a model rendered by a GameObject. I wish to add a small 2D icon at the upper right corner of the model. How do I get the 2D screen position of that point? (I'll be using OnGUI to render the icon in a label once I find the position)

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
0

Answer by DanjelRicci · Jun 11, 2011 at 07:52 AM

It's actually very easy. Use: Camera.WorldToScreenPoint in your object to obtain its position on the screen. You can find the documentation here.

Comment
Add comment · Show 5 · 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 Bunny83 · Jun 11, 2011 at 12:31 PM 0
Share

Well, that would give you the center point of your model... not the upper right corner

avatar image Bunny83 · Jun 11, 2011 at 12:47 PM 0
Share

Renderer.bounds will give you the axis aligned bounding box in world space. you could use WorldToScreenPoint with the corners and pick the upper right.

http://unity3d.com/support/documentation/ScriptReference/Renderer-bounds.html

avatar image DanjelRicci · Jun 11, 2011 at 08:54 PM 0
Share

Bunny83, once you got the (X,Y) coordinates of the center point with Camera.WorldToScreenPoint, you can simply draw the icon at (X+A,X+B) where A and B are the right values to make the icon appear at the top-right corner.
This will work well enough in every situation, unless you need an extremely precise position.

In that case, here's another good solution.
Create another GameObject (wich we can call "iconPos") and make it children of the GameObject wich you want to draw the icon on. Then, adjust "iconPos" transform's position in order to place it at the top-right corner of your parent object. Then, use Camera.WorldToScreenPoint to get the screen position of iconPos and draw the icon directly there.

avatar image Extrakun · Jun 12, 2011 at 07:54 AM 0
Share

@$$anonymous$$r Drayton, how do I find the right A and B value?

avatar image DanjelRicci · Jun 13, 2011 at 10:37 AM 0
Share

@Extrakun you should try yourself, A and B depends on the object visual size and screen proportions. Let's say that (X+70,Y+70) will shift the icon towards that top-right corner, but you have to change A and B to make the icon appear ON the top-right corner.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How To Open GUI Editor? 1 Answer

networkview + GUI 2 Answers

Why are all my GUITexture elements semi-transparent? 0 Answers

How to display textures that are in an array? 1 Answer

gui text button dont work 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