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 3dhelsel · Mar 26, 2014 at 07:26 AM · gui buttonscreen.width

placing a GUI.Button at a specific place on multiple screen resolutions

I have looked into this extensively and can not find a solution. I need to place Gui buttons over objects in the scene. I have used screen.width percentage solutions but as the resolution changes more or less of the scene is visible thus changing the percentage that it is from the corner of the screen.

Comment
Add comment · Show 1
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 3dhelsel · Mar 26, 2014 at 07:35 AM 0
Share

An example of what I've tried{
ButtonPosHor= Screen.width-Screen.width*HorizontalPos ; ButtonPosVert = Screen.height-Screen.height*VerticalPos ;}

2 Replies

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

Answer by Patel-Sagar · Mar 26, 2014 at 09:40 AM

You can use Camera.WorldToScreenPoint("your object position")

it will set in every resolution and you can set your button depending on this returned position.

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 Bunny83 · Mar 26, 2014 at 10:04 AM 0
Share

Right, keep in $$anonymous$$d that the screenspace y-position is reversed compared to the GUI position. The screenspace has 0,0 at the bottom-left-corner while the GUI space has 0,0 at the top-left-corner. So you need to subtract the y position from Screen.height to get the position in GUI coordinates.

avatar image 3dhelsel · Mar 26, 2014 at 06:51 PM 0
Share

Ah yes! That sounds like it would work. Thank you Patel && Bunny!!

avatar image 3dhelsel · Mar 26, 2014 at 10:52 PM 0
Share

I've used that technique and it works great! thanks again!!

avatar image
1

Answer by RedDevil · Mar 26, 2014 at 07:33 AM

I too had this problem the past week but i found the solution on a youtube video + an answer from unity answers:

     GUI.Box (Rect (0,0,100,50), "Top-left");
     GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
     GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
     GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");

Using these the buttons will be on same place and you use Button instead of Box. If you want for example Bottom left more to the left or right you just change the second value of Screen/height -50 to more - or more +.

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 3dhelsel · Mar 26, 2014 at 07:42 AM 0
Share

Thanks but that's not exactly what I am ai$$anonymous$$g to do. You see I don't need them in the same pos on the screen I need them to be over an item in the scene. I was tring to use the screen.width/height percentage method to do it but that still only gets the button over the object for the resolution I set it for.

avatar image HariKrishnan · Mar 26, 2014 at 10:09 AM 0
Share

u can use flag variable for each screen. then screen value using to display button.

avatar image 3dhelsel · Mar 26, 2014 at 10:29 AM 0
Share

Are you suggesting that I set a unique position for all possible screen resolutions?

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

24 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

Related Questions

Detect touch in screen at different resolutions 2 Answers

How to turn on/off multiple lights using GUI buttons? 1 Answer

Dark-Style gui.button 0 Answers

Do screen.width and screen.height get updated depending on screen orientation on Android? 1 Answer

Screen.width/Screen.height not working with multiple resolutions 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