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 menep · May 16, 2012 at 02:39 PM · guiwindowcenterwindowed

Center GUI wondow or box in windowed mode

I made a window using:

 new Rect ( (Screen.width - (Screen.width/2) ), 100 , 600, 600);


But it doesnt center in windowed mode.

Im trying to make a main menu showing and hiding different windows. Everyone is using different resolution so its important.

Also a good idea would be to use dynamic size of a box and buttons.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sath · Jan 08, 2014 at 03:46 PM

for a GUI box(or Label) 600x600 size, you can say that 600 = Screen.height*0.6f so it will be

 new Rect(Screen.width*0.5f-Screen.height*0.3f,Screen.height*0.5f-Screen.height*0.3f, Screen.height*0.6f,Screen.height*0.6f)

the start point of your GUI box is at top left corner so the center of it , will be in the center of screen for any screen size**

better than that is

     //adjust your values here to select the desired size for your Box or Label
     //in Play Mode you can see directly your changes after saving script first
     float boxWidth=Screen.height*0.6f;
     float boxHeight=Screen.height*0.6f;
     
     //Now with the given values make the dot for draw start potision(top left corner)
     float startBoxWidth=Screen.width*0.5f - boxWidth*0.5f;
     float startBoxHeight=Screen.height*0.5f - boxHeight*0.5f;
     
     //and finally 
     new Rect(startBoxWidth,startBoxHeight, boxWidth,boxHeight)
     
     //this can be done also for GUI.Label ,Box , Button etc.
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
avatar image
0

Answer by Piflik · May 16, 2012 at 02:47 PM

First, Screen.width - Screen.width/2 is the same as Screen.width/2...

Second, the position of a Rect specifies the position of its upper left corner. So to center a Rect on the screen, you'd have to subtract half of the Rect's width from the position.

 new Rect(Screen.width/2 - 300, 100, 600, 600);
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
avatar image
0

Answer by Rgalaxy · Jan 08, 2014 at 03:37 PM

i've trying to accomplish this.. i think its not Screen.width/2 - 300

i try to find the math but i comes up with this to make it center of the screen..

 new Rect(Screen.width-(Screen.width-300))/2 , Screen.height-(Screen.height-300))/2 , 600,600);


this should makes the box which is 600x600 placed on the center of the screen. CMIIW..

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Window problem 2 Answers

GUI Window on GameObject location? 1 Answer

Stop clicking through a GUI window 2 Answers

Don't show window close button 1 Answer

GUI.Window only shows for one frame under all circumstances 2 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