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 /
This question was closed Apr 20, 2013 at 08:26 PM by Eugenius for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Eugenius · Dec 24, 2012 at 02:07 PM · guigameobjectpositionrelative

Is it possible to position a GameObject as relative to a GUI?

Hello again guys ^_^.

I would like to know if its possible someway to position a GameObject in the same position as a GUI (a GUI box for example)? And at the same time if it can scale/move as the GUI does?

To be more specific I'd like the Game Object to appear within the limits of the GUI Box and scale/position itself accordingly.

Keep in mind that the GUI Box that I've defined is already scaling/positioning itself according to the screen resolution/ aspect ratio.

Regards, Eugen

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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by efge · Dec 24, 2012 at 03:29 PM

First get the rect of the GUI element and its center using GUIElement.GetScreenRect() and Rect.center.

Transform the point from screen space into world space with Camera.ScreenToWorldPoint.

Then you could calculate a scale factor for x and z using Screen.width, Rect.width and Screen.height, Rect.height.

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 Eugenius · Dec 25, 2012 at 10:36 AM 0
Share

I'm currently attempting to put together the proper code. Once I get it I will let you know if it worked. I know that it's the proper method of making it work but I just have to figure out a couple of more variables. Thanks for the answer!

avatar image Eugenius · Dec 25, 2012 at 11:02 AM 0
Share

How can I use the GUIElement.GetScreenRect() function if I am using a Texture2D on my GUI Box? I've made up this code: "var r : Texture2D = AvatarBackground.GetScreenRect(); Debug.Log("AvatarBackground are" + r.width + "si inaltimea de" + r.height);"

Where AvatarBackground is defined at the beginning of the script as Texture2D. I've also tried the same code but with: var r : Rect =... and still to no avail. I keep on receiving the same error: $$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'UnityEngine.Texture2D.GetScreenRect'.

avatar image
1

Answer by Bunny83 · Dec 25, 2012 at 12:45 PM

GUIElements like GUITexture and GUIText are the "old" GUI system. If you use OnGUI and the GUI / GUILayout class, you have to use GUIUtility.GUIToScreenPoint and then you could use Camera.ScreenToWorldPoint to bring the coordinates into workspace.

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How to give a relative position to a GUI Texture ? 2 Answers

GUI Button and a gameObject's position 3 Answers

gui position of Screen relative position 2 Answers

Hi everone! I am new to Unity so sorry if this question stupid. But basically can you help me fix the Code? 1 Answer

Is it possible to move relative position of GUI? 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