- Home /
[Closed]GUI.DrawTexture inside GUI.DrawTexture
maybe it is an odd question but what i try to accomplish here is..
i create a GUI.DrawTexture showing a whiteboard, and here's the code
public var background1 : Texture;
var btn_next : Texture;
function OnGUI(){
GUI.DrawTexture(Rect((Screen.width-(Screen.width/4*3))/2,
(Screen.height-(Screen.height/4*3))/2, //this is to center the Rect
Screen.width/4*3, Screen.height/4*3),background1);
GUI.DrawTexture(Rect(200,100,40,20),btn_next);
//btn_next must be at right-lower corner of whiteboard.
}
and then i want to Draw again a texture of Next Button, but i want to Draw it Inside the background 1.. so i will not put it bluntly on the screen.. because it will cause the button takes different place on different mobile resolution..
Thanks before for any solution given here..
Answer by sath · Jan 08, 2014 at 11:03 PM
First of all:
Screen.width-(Screen.width/4*3))/2 = Screen.width *0.125
Screen.height-(Screen.height/4*3))/2 = Screen.height * 0.125
Screen.width/4*3 = Screen.width*0.75
Screen.height/4*3 = Screen.height*0.75
#pragma strict
var background1 : Texture;
var btn_next : Texture;
//background image dot start rect point
var backX : float;
var backY : float;
//background image size
var backWidth : float;
var backHeight : float;
//button image dot start rect point
var buttonX : float;
var buttonY : float;
//button image size
var buttonWidth : float;
var buttonHeight : float;
function OnGUI(){
backX = Screen.width *0.125;
backY = Screen.height * 0.125;
backWidth = Screen.width*0.75;
backHeight = Screen.height*0.75;
buttonWidth = Screen.width*0.06;
buttonHeight = Screen.height*0.05;
buttonX = Screen.width *0.875 - Screen.width*0.06; //(backX + backWidth)- buttonWidth
buttonY = Screen.height *0.875 - Screen.height*0.05; //(backY + backHeight)- buttonHeight
GUI.DrawTexture(Rect(backX,backY,backWidth, backHeight),background1);
GUI.DrawTexture(Rect(buttonX,buttonY,buttonWidth,buttonHeight),btn_next);
//btn_next now it is at right-lower corner of whiteboard !!!
}
another option if you have more than one buttons is to use GUI.BeginGroup
wow, this is good ! btw, @sath i create a serial of tutorial, that when i click next, the background image change to next image, does i should just call the new GUI.DrawTexture? or it's better for me to erase the last image first?
because i want the tutorial serial is able to go back and forward..
the background image is that board with the scratch (it was 1 image created in photoshop), and the next_btn is like that in the corner-right.. does the button should be a GUI.Button ins$$anonymous$$d?
Yes in this case the next_btn must be a GUI.Button(assume you know how)but if you have many backgrounds you must disable previous image before the next enabled and you need a previous_btn. You can use booleans in your OnGUI function were you can say if that btn pressed then next=true and GUI.backround = 1 etc.. If you feel that you need help on that it is better to open another Question as this one is answered and it is better to accept it as correct so everyone that may have the same problem can found a solution here..
Thanks you so much @sath, i will try it first with your guide and if i encounter any problem i will try to ask it here on another question ! :)
Your answer
Follow this Question
Related Questions
Fade between textures in the same script? 3 Answers
Texture on center bottom of screen 3 Answers
Setting Scroll View Width GUILayout 1 Answer
GUI.Drawtexture Overlaping Other GUI.Drawtexture. 1 Answer
How to change rect size? 2 Answers