- Home /
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
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;
}
}
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.
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
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..
i imagine but i don't understand how ... what 6.55 represent? just arbitrary value?
Your answer
Follow this Question
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