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 Kalu · Feb 23, 2012 at 06:51 PM · guiscreendrawtexturefit

drawTexture background fit screen

Hello, I have wallpaper that I draw with drawTexture, my concern is to handle different screen sizes. The size of the application is generated when the user opens the web page (compared to the size of the screen) it is necessary that the images in full screen have the right size. I find some code with Matrix4x4 but i dont have any goo result. I just want that image full size in 1080x1920 screen same as 1100 or other resolution .. thx

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
0
Best Answer

Answer by Kalu · Feb 24, 2012 at 02:42 PM

Fixed with this code.

 if(b_help_mode){
             float horizRatio = Screen.width / 1000f;
             float vertRatio = Screen.height / 700f;
             Vector3 vect = new Vector3 (0f, 0f, 0f);
             Vector3 vect1 = new Vector3 (horizRatio*1f, vertRatio*1f, 1f);
             GUI.matrix = Matrix4x4.TRS (vect, Quaternion.identity, vect1);
 
             if(s_help_menu == "sauvegarde"){
                 GUI.DrawTexture(new Rect(0, 0, save_helpscreen.width, save_helpscreen.height), save_helpscreen);
             }else if(s_help_menu == "creation"){
                 GUI.DrawTexture(new Rect(0, 0, create_helpscreen.width, create_helpscreen.height), create_helpscreen);
             }else if(s_help_menu == "librairie"){
                 GUI.DrawTexture(new Rect(0, 0, librari_helpscreen.width, librari_helpscreen.height), librari_helpscreen);
             }else if(s_help_menu == "none"){
                 GUI.DrawTexture(new Rect(0, 0, acceuil_helpscreen.width, acceuil_helpscreen.height), acceuil_helpscreen);
             }
             GUI.skin = customSkinMenusLeftSide;
             if(GUI.Button(new Rect(8f, Screen.height-8f-110f, 55f, 55f), i_close_help)){
                 b_help_mode = false;
             }
         }
Comment
Add comment · Show 1 · 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 Kalu · Feb 24, 2012 at 02:43 PM 0
Share

1000 & 700 represent your image dimention.

avatar image
0

Answer by sgmongo · Feb 23, 2012 at 11:16 PM

When you draw the texture, it asks for a Rect.

This gives the texture its position and its width and height.

Replace the values of width and height with Screen.width and Screen.height respectively.

Example code:

 var yourtexture : Texture2D
 
 function OnGUI(){
      GUI.DrawTexture (Rect (0, 0, Screen.width, Screen.height), yourtexture);
 }

The GUI.DrawTexture function has a few more handles that allow you to adjust how it scales and the like. Here is a link the to literature :

file:///C:/Program%20Files%20(x86)/Unity/Editor/Data/Documentation/Documentation/ScriptReference/GUI.DrawTexture.html

The reason this scale is because Screen.width, and Screen.height are read only values of the current screen size being used by unity.

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 robert_mathew · Feb 23, 2012 at 08:57 PM

 GUI.DrawTexture(Rect(Screen.width *(1f/6.55f),Screen.height *(0.1f/6.3f),Screen.width * (4.8f/6.55f), Screen.height *(0.85f/6.3f)), aTexture, ScaleMode.ScaleToFit, true, 10.0f); //java script


 GUI.DrawTexture(new Rect(Screen.width *(1f/6.55f),Screen.height *(0.1f/6.3f),Screen.width * (4.8f/6.55f), Screen.height *(0.85f/6.3f)), aTexture, ScaleMode.ScaleToFit, true, 10.0f); //c#

this will adjust the all GUI what ever the screen reslotion.if it sloved your problem means do not forget to upvote

Comment
Add comment · Show 3 · 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 Kalu · Feb 23, 2012 at 09:16 PM 0
Share

the texture is more or Less in the middle but its height is very small and its width does not take the entire screen. don't understand what value mean so i can't try other setting..

avatar image robert_mathew · Feb 24, 2012 at 03:33 AM 0
Share

adjust the height and width

avatar image Kalu · Feb 24, 2012 at 02:15 PM 0
Share

i imagine but i don't understand how ... what 6.55 represent? just arbitrary value?

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

7 People are following this question.

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

Related Questions

Resizable GUI box how to? 1 Answer

Filling the screen doesn't... 1 Answer

GUI texture to fit the screen at any resolution? 4 Answers

Android Button Screen 1 Answer

Using Grayscale Textures For Transparency 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