• 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
Question by Showken · Nov 15, 2010 at 06:31 AM · guipositionscreenrelative

gui position of Screen relative position

I have set a gui position with "Screen.width*,Screen.height *",but when I resize the Screen window,the gui didn't move to relative position .why?

        GUI.BeginGroup(new Rect(Screen.width-470, Screen.height-66, 470, 66));
    GUI.skin=tiaoskin;
    GUI.Label(new Rect(0,15,470,51),"");
    GUI.skin=geoskin;
    if(GUI.Button(new Rect(10,25,75,36),""))
    {
        MoveToArea(geoposition);
    }
    GUI.skin=touskin;
    if(GUI.Button(new Rect(90,25,58,36),""))
    {
        MoveToArea(touposition);
    }
    GUI.skin=cityskin;
    if(GUI.Button(new Rect(160,25,53, 36),""))
    {
        MoveToArea(cityposition);
    }
    GUI.skin=ecoskin;
    if(GUI.Button(new Rect(230,25,60, 36),""))
    {
        MoveToArea(ecoposition);
    }
    GUI.skin=humskin;
    if(GUI.Button(new Rect(310,25,65, 36),""))
    {
        MoveToArea(humposition);
    }
    GUI.skin=helpskin;
    if(GUI.Button(new Rect(390,32,19, 24),""))
        Movehelp(false);
    if(isvoice)
    {
        GUI.skin=voiceonskin;
        if(GUI.Button(new Rect(430,32,31, 24),""))
        {
            voicetemp.audio.mute=true;
            isvoice=false;
        }
    }
    else
    {
        GUI.skin=voiceoffskin;
        if(GUI.Button(new Rect(430,32,31, 24),""))
        {   
            voicetemp.audio.mute=false;
            isvoice=true;
        }
    }
    //
    if(isflash)
    {
        GUI.Label(new Rect(225,0,200,30),flashimg);
    }
    GUI.EndGroup();
Comment

People who like this

0 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 matyicsapo · Nov 15, 2010 at 06:42 AM 0
Share

i don't know about others but I'd need to see the actual gui command's code to be able to tell the problem

avatar image Showken · Nov 16, 2010 at 06:17 AM 0
Share

have already showed the code,think you!

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by matyicsapo · Nov 16, 2010 at 07:15 AM

The (0,0) point in GUI is the top-left corner.

Your buttons move horizontally though maybe not the way you want. I suggest you change your magic numbers atleast for the values of the group to public variables atleast or do somekinda calculation like where is the center of the screen or whatever.

But the reason your controls don't move vertically is that the Screen.height may change, but you always subtract the same value from this changing Screen.height. Of course 500-66=434 and 200-66=134 so you that it should be at a different position. But the maximum of Screen.height is always the bottom of the screen. And you always subtract the same value 66 in your example. That is it will always be 66units away from the bottom of the screen. Which is true as you can see too.

Hope that was clear enough that it helped.

Comment

People who like this

0 Show 0 · 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

Answer by FreeTimeDev · May 10, 2011 at 11:34 AM

GUI.BeginGroup(new Rect(Screen.width-470, Screen.height-66, 470, 66));

Screen.width:

0% = Left side. 100% = Right side.

Screen.height:

0% = Top. 100% = Bottom.

If you ALWAYS want your group to be in a specific spot on screen regardless of resolution you cannot use absolute numbers in your code. Your code should probably look something like:

GUI.BeginGroup(new Rect(Screen.width*<Some Number>, Screen.height*<Some Number>,
 Screen.width*<Some Number>, Screen.height*<Some Number>));

(Some Number is between 0 and 1, like .5)

This is because, obviously, different resolutions have a different number of pixels. So when you say you want it 500 pixels from the right side of the screen that's almost on the left side of the screen in a Web Player, or middle-right side in a Full screen application.

Comment

People who like this

0 Show 0 · 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

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

No one has followed this question yet.

Related Questions

how to have an object positioned relative to the screen(like a button) 1 Answer

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

How to set the position of a guitext using transform? 1 Answer

Is there a way to lock GUI buttons to a screen position insted of a pixel defined position so it will show up no matter the resolution of the screen? 0 Answers

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