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 ShizumiNelo · Jan 27, 2013 at 08:21 AM · guiresolutionscreenfixed

Fixed to the screen GUI ?

Hello everyone at Unity Answer, I have a GUI script for a gun hud but when the screen resolution changes the hud moves i wont it to say in one place. The script i'm useing is this.

 function OnGUI (){
     if(selected){
         GUI.skin = mySkin;
         var style1 = mySkin.customStyles[0];
         if(ammoMode == Ammo.Magazines){
             if(firstMode != fireMode.none && firstMode != fireMode.launcher || secondMode != fireMode.none && secondMode != fireMode.launcher){
                 GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Ammo : ");
                 GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
                 GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," / " + magazines);
             }
         }    
         
         if(ammoMode == Ammo.Bullets){
             if(firstMode != fireMode.none && firstMode != fireMode.launcher || secondMode != fireMode.none && secondMode != fireMode.launcher){
                 GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"Bullets : ");
                 GUI.Label (Rect(Screen.width - 110,Screen.height-35,200,80),"" + bulletsLeft, style1);
                 GUI.Label (Rect(Screen.width - 80,Screen.height-35,200,80)," |  " + magazines);
             }    
         }
         
         if(firstMode != fireMode.none || secondMode != fireMode.none){
             GUI.Label (Rect(Screen.width - 200,Screen.height-65,200,80),"Firing Mode :");
             GUI.Label (Rect(Screen.width - 110,Screen.height-65,200,80),"" + currentMode, style1);
         }
         
         if(secondMode == fireMode.launcher || firstMode == fireMode.launcher){
             GUI.Label (Rect(Screen.width - 200,Screen.height-95,200,80),"Projectiles : ");
             GUI.Label (Rect(Screen.width - 110,Screen.height-95,200,80),"" + projectiles, style1);
         }    
         
         if(crosshairFirstModeHorizontal != null){    
             if(currentMode != fireMode.launcher){
                 var w = crosshairFirstModeHorizontal.width;
                 var h = crosshairFirstModeHorizontal.height;
                 position1 = Rect((Screen.width + w)/2 + (triggerTime * adjustMaxCroshairSize),(Screen.height - h)/2, w, h);
                 position2 = Rect((Screen.width - w)/2,(Screen.height + h)/2 + (triggerTime * adjustMaxCroshairSize), w, h);
                 position3 = Rect((Screen.width - w)/2 - (triggerTime * adjustMaxCroshairSize) - w,(Screen.height - h )/2, w, h);
                 position4 = Rect((Screen.width - w)/2,(Screen.height - h)/2 - (triggerTime * adjustMaxCroshairSize) - h, w, h);
                 if (!aiming) { 
                     GUI.DrawTexture(position1, crosshairFirstModeHorizontal);     
                     GUI.DrawTexture(position2, crosshairFirstModeVertical);     
                     GUI.DrawTexture(position3, crosshairFirstModeHorizontal);     
                     GUI.DrawTexture(position4, crosshairFirstModeVertical);        
                 }
             }
         }    
     


Could someone help me ?

Thank you for your time, Have a nice day.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GuyTidhar · Jan 27, 2013 at 11:44 AM

Try using GUI.Matrix instead of positioning according to the current width or height. This will stretch or shrink your whole GUI:

 float originalWidth = 1024; // Design resoultion
 float originalHeight = 768;
 void OnGUI()
 {
   // Set matrix
   Vector2 ratio = new Vector2(Screen.width/originalWidth , Screen.height/originalHeight );
   Matrix4x4 guiMatrix = Matrix4x4.identity;
   guiMatrix.SetTRS(new Vector3(1, 1, 1), Quaternion.identity, new Vector3(ratio.x, ratio.y, 1));
   GUI.matrix = guiMatrix;
  
   // Do you GUI here
  
   // Reset matrix
   GUI.matrix = Matrix4x4.identity;
 }

Don't forget to NOT use the Screen.width or Screen.height within your GUI functions if you use this.

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

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

Fixed Screen Resolution 2 Answers

Player Screen Resolution 2 Answers

Clamping after forcing aspect ratio 0 Answers

Fit GUI to various android screen resolutions and densities 6 Answers

NOT auto resizing GUI, keeping GUI always the same aspect ratio 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