- Home /
gui refresh render
Hi,I have two situations and for each a GUI. A variable controls whether a button will show text only or with only a icon button.
var imageText : boolean = true;
//button that control if(GUI.Button (Rect (10, 210, 100, 15), "IMAGE OU TEXT")) { imageText = !imageText; }
if(imageText == true) { if (GUI.Button (Rect (5, 100, 50, 50), icon)) { }
}else{
if (GUI.Button (Rect (5, k, 50, 50), text)) {
}
}
the problem is that I even turning the button("IMAGE OU TEXT") and the control variable being altered my render no change of icon to text.
Answer by diabloroxx · Sep 02, 2010 at 09:15 PM
I just tested out your code. The problem occurs because as soon as OnGUI() is called, it looks at the Boolean value and immediately prints the GUI Button. So in effect there are 3 Gui Buttons being loaded. So the one with Icon is always loaded first. I modified the code where you actually check whether it is ready to load the GUI. Hope it helps.
var imageText : boolean = true; var icon : Texture2D; var readytoload = 0;
//button that control function OnGUI(){
if(GUI.Button (Rect (10, 210, 100, 15), "IMAGE OR TEXT")) { readytoload = 1; imageText = !imageText; Debug.Log(imageText); }
if(readytoload) { if(imageText) if (GUI.Button (Rect (5, 100, 50, 50), icon)) { imageText = true; Debug.Log("Icon"); Debug.Log(imageText); }
if(!imageText) { if (GUI.Button (Rect (205,100, 50, 50), "Text")) { imageText = false; Debug.Log("Text"); Debug.Log(imageText); } } } }
I did not understand well. a simple X causes a delay in the GUI. is it? Because the readytoload value not change
No it is not about the delay. Initially when OnGUI() is called, it automatically renders the GUI with Icon as the default value of imageText is true. When we change the condition of the imageText to (false), then the GUI-Text is rendered. Again when the condition is changed, (imagetext is set to True) the GUI Icon is rendered ins$$anonymous$$d of the currently created GUI Text. So in essence there are 3 GUI buttons. 1. The one which is initially created. 2. The GUI Text button. 3. GUI Icon button.
The only work around is to check if you need one GUI Button as soon as the OnGUI is loaded.
Your answer
Follow this Question
Related Questions
Drawing a GUI.DrawTexture call above GUI.Button in seperate scripts 0 Answers
Can i render a camera to a gui texture? 1 Answer
How should I generate an image of a model? 1 Answer
how to render line between gui element and mouse position 1 Answer
What GUI method renders 3D object thumbnail previews in the editor? 1 Answer