- Home /
more guitexture in void ongui
I have to put multiple images on the screen (GUITexture) but as soon as I press play these images appear all at once, I would like to know: what the script to disable all the scripts to run only the image with a given name?
Answer by YoungDeveloper · Aug 15, 2013 at 06:56 PM
You should use OnGUI(), you can control gui textures or any other data in OnGui function using Bools.
if(showpicture1){
//gui picture 1 stuff }
if(showpicture2){
//gui picture 2 stuff }
you can write the full script? For example I have the images "help" and "help2" as the off / on?
public Texture2D help1; //drag image help 1 here
public Texture2D help2; //drag image help 2 here
bool show_help1;
bool show_help2;
void Start(){
//images wont show as default
show_help1 = false;
show_help2 = false;
}
void Update(){
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0)){
show_help1 = true;
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.$$anonymous$$ouse0)){
show_help1 = false;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse1)){
show_help2 = true;
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.$$anonymous$$ouse1)){
show_help2 = false;
}
}
void OnGUI(){
if(show_help1 == true){
GUI.DrawTexture(new Rect(Screen.width-help1.width, Screen.height/2,help1.width,help1.height),help1);
}
if(show_help2 == true){
GUI.DrawTexture(new Rect(0, Screen.height/2,help2.width,help2.height),help2);
}
If you will hold down left mouse button, you will see help 1 image. But on right mouse button hold you will see help2 image.
the script works ok but how do I correctly position the image at the top right of the screen?
Please read the docs before asking, i have a feeling that you are not even trying to understand. Everything you need is I already mentioned and even coded for you. http://docs.unity3d.com/Documentation/ScriptReference/Rect.html
GUI.DrawTexture(new Rect(//distance from left screen side, //distance from upp screen side, //gui box width, gui box height), //image to show );
So to get it on top right corner:
GUI.DrawTexture(new Rect(Screen.width - help1.width, 0 , help1.width , help1,height),help1);
And remember to accept my answer.