- Home /
Switching GUI on and off
hi
i normally use a bool value to swicth my windows on and off, does anyone know of another way to switch them on and off?
the script i use:
function OnGUI() { if (windowOpen) { GUI.skin = mySkin; OrbInstantiate.freezed = true; windowRect = GUILayout.Window(0,windowRect,DoMyWindow,"Orb Info");
if (addComment)
{
windowComment = GUI.Window(0,windowComment,CommentWindow,"Orb Info");
}
thanks!
Answer by Ashkan_gc · May 13, 2010 at 09:49 AM
you can use bool values as you said. you can make the gameobject that has the gui active/inactive too. use the active property. also you can enable/disable the component that has the gui with enabled property. the unity GUI system is a low level system. you can create classes for GUI and expose properties like visible for them and use things like this
if (visible == true)
{
//call the GUI method like GUI.Button ()
}
also you can expose other properties like letf/top and width/height and value and ... a GUI Element class would look like
class GUIElement
{
public bool visible;
public float left,top,width,height;
public string name;
GUIElement (string s)
{
name = s;
}
virtual Draw ()
}
then you should have a form class that you add other elements to it and it will call the draw method of all gui elements inside it in it's onGUI
class form : MonoBehaviour { private List elements = new List();
void OnGUI () { foreach (GUIElement g in elements) { g.Draw(); } } } then you should define classes for Button and TextField and ... that they are children of GUIElement and define their own Draw methods that use the properties to draw the control a draw method for a button would use a GUI command like this
if (GUI.Button (new Rect(left,top,width,height),name))
{
}
you can have a deligate to call when this happens and also form class can have methods for creating a button and label and adding the created element to the list
you can create XML file structures to read and create GUI based on them and many more
ok the prob i'm having is:
i have multiple gameobjects that instantiates at runtime. each object gets assigned an id and has a GUI/window script on it. when i click on an object i want it to display the current id for the object. but now its displaying the last id that was assigned to the last gameobject that got instantiated. how do i go about getting this right?
use a static variable in a class and put the id of the clicked object in the static var and show that var.
Is this answer correct/still relevant? As far as I know OnGUI and GUIElement are two different GUI systems. Correct me if I'm wrong.
Your answer
Follow this Question
Related Questions
weapon switching 1 Answer
Switching weapons/tools using a GameObject array 2 Answers
switch scripts? 1 Answer
GUI Script switching on and off. 1 Answer
gun switch script 26-feb-2010 1 Answer