• 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 PaxForce · Nov 17, 2014 at 06:08 PM · relativegui.begingroup

GUI.Box position RELATIVE to GUI group

Is it possible to position a GUI element inside the GUI group relative to IT's position? Like we can position it relative to screen. e.g.: Screen.width/2 Can be something done with an element inside a GUI group? e.g.:

 GUI.Box(new Rect(BeginGroup.width/2, BeginGroup.height/2, 100, 100), "");

...or something to this effect.

Comment
Add comment · Show 7
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 Addyarb · Nov 18, 2014 at 12:36 AM 0
Share

Just access the variables and divide/multiply them as you please. Or even better make a reference in the update function in-case they resize or something.

avatar image PaxForce · Nov 18, 2014 at 08:10 AM 0
Share

@Addyarb - I don't understand what you mean by that. I need it to be relative to it's parent GUI group...

avatar image incorrect · Nov 18, 2014 at 09:10 AM 0
Share

Or you can try new uGUI introduced in Unity 4.6. You will see that it is much easier and intuitive to make GUI this way.

avatar image PaxForce · Nov 18, 2014 at 02:54 PM 0
Share

there is no such thing as Unity 4.6 yet. see for yourself.

avatar image incorrect · Nov 18, 2014 at 03:05 PM 0
Share

There is Unity 4.6 beta, see for yourself. Do you even watch the main webpage?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Immanuel-Scholz · Nov 18, 2014 at 03:19 PM

The "cleaniest" way is to wrap GUI.BeginGroup / GUI.EndGroup with your own functions and remember the rectangles passed. This way you can calculate the "current group width".

Wrapping these functions is never a bad idea, it will come in handy when you try to debug group mismatches and other hazzles you will have with the old OnGUI()

If you don't want to do that yourself, you can access an hidden function from Unity via Reflection:

 Vector2 GetCurrentGUIGroupWidthHeight()
 {
     Type t = System.Type.GetType("UnityEngine.GUIClip, UnityEngine");
     Rect r = (Rect)t.GetProperty("topmostRect").GetValue(null, null);
     return new Vector2(r.width, r.height);
 }

Although.. if you are just new to Unity GUI, do yourself a favour and download Unity 4.6 RC1 and use the new Unity UI. Much easier.

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 PaxForce · Dec 11, 2014 at 10:26 AM 0
Share

Is not the beta version of Unity (the 4.6) stable? Is it not prone to crashing more frequently? Just asking... Which Unity do YOU use?

avatar image incorrect · Dec 11, 2014 at 05:36 PM 0
Share

@PaxForce, 4.6 is no longer in beta, it was released.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

28 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 avatar image avatar image avatar image avatar image

Related Questions

Can WWW do relative URLs? 1 Answer

Imported model is rotated 90 degrees off of straight, can't use any transforms 1 Answer

How do I reset the mousePosition relative to an object I click on? 1 Answer

Add force in the camera direction?? 1 Answer

Rotate a Cube by 90 degree 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