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 Giannis7312777 · Jul 21, 2013 at 08:12 PM · positionscreen

GUI box fit in all screens

Hello everyone! I made a GUI box and I want the position to be the same in all kind of screens. Code:

 GUI.Box(new Rect(Screen.width / 2 - m1, Screen.height / 2 - m2, healthBarLength, 20), "");

In the little window on the editor I fit the corrent position. When I change my resolution to Full Screen my box changes position. How can I fix it?

Thanks, any help is appriciated! :)

Comment
Add comment · 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 Jamora · Jul 21, 2013 at 08:19 PM 0
Share

What are m1 and m2? Are they dependant on the resolution?

avatar image Giannis7312777 · Jul 22, 2013 at 07:22 AM 0
Share

These are variables which I can move my health bar

2 Replies

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

Answer by tw1st3d · Jul 21, 2013 at 09:09 PM

I don't know how well this will work, but I'd do something like this.

 using UnityEngine;
 using System.Collections;
 
 class HUD_Display : MonoBehavior
 {
     
     public GUIStyle customStyle;
     
     void OnGUI()
     {
         GUI.skin = customStyle;
         int healthBarLength = 200;
         
         GUI.BeginGroup(0, Screen.height - 20, Screen.width, 20); 
             GUI.Box(new Rect(0, 0, healthBarLength, 20), "");
         GUI.EndGroup();
     }
     
 }

Create a GUI group at the bottom of your screen(or wherever you want it), and then create your health bar inside of that. Use absolute positions for creating the box, instead of multiple effectors on the Y position. I.E. Screen.height - Specific Amount Only

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 Giannis7312777 · Jul 22, 2013 at 07:30 AM 0
Share

Any ideas how to do this on JS ?

Thankks in advance

avatar image reppiz01 · Jul 22, 2013 at 12:50 PM 2
Share

try to use google or read the manual ;)

http://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginGroup.html

avatar image
0

Answer by reppiz01 · Jul 22, 2013 at 07:31 AM

if you have a "fix" aspect ratio you could try this:

     GUI.matrix = Matrix4x4.TRS (Vector3.zero,
                                    Quaternion.identity,
                                    new Vector3 (Screen.width / scrW, Screen.height / scrH, 1));


in my case scrW is 1920, and scrH is 1080.

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

18 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

Related Questions

UI RectTransform Position && Screen Resolution 2 Answers

Touch.position, Touch.deltaPosition, Screen.width, Screen.Height 1 Answer

x0,y0 doesn't always point to the bottom left corner 1 Answer

How to set position of 4 gameobjects at the bottom of the screen? 1 Answer

Mouse.position from center of player 1 Answer


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