the docs do a very good job at explaining how to make gui elements, but i am having a hard time understanding how to connect them to game objects and componants.
can someone point me to a simple code example of moving a slider and then having something like a box move or a color change to illustrate the connection?
man, i wish unity came with more working examples.
AngryAnt, i see what you are getting at, but still dont know how i would get this to work with the following code that does nothing but “make” a slider. i would so gladly pay for a book written by someone experienced with Unity.
var hScrollbarValue : float;
function OnGUI () {
hScrollbarValue = GUI.HorizontalScrollbar (Rect (25, 25, 100, 30), hScrollbarValue, 1.0, 0.0, 10.0);
//make something happen related to the slider
}
The thing is, that due to the untraditional nature of the unity GUI system, you need to scrap some old ideas on how GUI is done and adopt some new ones.
The OnGUI function is where your GUI is updated twice per frame and once per event (mouse and keyboard events etc.). You should view this function as where you layout and render your GUI plus where you connect your internal variables to it.
Nothing but directly GUI related code should be run in OnGUI.
The handling of the values of the internal variables variables should take place in other functions - for instance Update or FixedUpdate.
Silly analogy: Its like an area where you’re able to design, set up and hook up a bunch of levers and buttons to the internals of your machine.