GUI variables

I looked on the unity answers, but nothing was what I wanted.
I also looked on the wiki, but didn’t find anything about variables.

anyways, my question is, how do I make a GUI a variable?

like how you make an interger you do int name_here

how would you make a GUI variable?

Define a ‘GUI variable’.

I’m asking someone else too.
Because I don’t know.

Like for a gameobject you write

GameObject var_name

but for a GUI what would you write?

GUI var_name; ?

Try GUIText instead of GUI

Heres my script:

Heres my error

Any other trys?

Daniel didn’t mean to literally replace your text with that, he means you should look into GUITexts.

Did you actually read this before trying and opening this thread?

Pop quiz, what’s the return value of GUI.Box?

And there is not such thing as a GUI variable. And it’s called integer btw, not interger. It’s not that hard.

The issue here seems to be a lack of understanding about what function calls do, what variables are, and how types work. GUI.Box(…) returns “void”, which means it doesn’t send any data back to where you called it from. In that snippet of code you’re trying to define a bunch of items of type GUIText and then assign a “void” to them, which can’t be done.

OnGUI() is used for what is called an “Immediate mode” GUI. That is to say, the various functions draw to the screen, collect input, or otherwise do what they do immediately. They don’t return objects to do things with later, which appears to be how you’re trying to use it. When you type…

GUI.Box(new Rect(10, 10, 100, 100), "Blah");[/quote]
... a box labelled "Blah" gets drawn to the screen when that code is run. At no stage are you ever given a reference to that box that gets drawn, because it only exists [I]while it is being drawn*[/I].

[SIZE=1]* This is a simplification, but I think it addresses the concepts that are important here.[/SIZE]

Well, I got intereted in it because someone posted here
http://answers.unity3d.com/questions/316838/gui-variable-declaration-problem.html
But, it was in javascript, and I don’t know that.

Yay, I figured it out, thanks

So… care to share it?

After asking for help in an online community it’s courteous and good form to come back and share your solution if you find one somewhere else or figure it out for yourself. The people helping you might not need it, but other people like you who search for it in the future might find it useful.

Ok, so, instead of making a GUI variable, you make a rectangle variable.
When you check for GUI.Button, just put this:

if(GUI.Button(Rect_Var_Name,“”)){
}

And it all works :smile:

Yep, that works. :slight_smile:

Do you understand why it works and what each bit of it is doing?

Yuppers.
It checks if an invisble box is clicked right where my gui is.
It is invisible because it was never made into a GUI.

Hmm… sort of. Collisions are always checked against “invisible” things because the collision data is distinct from the rendering data. But…

… I’m not sure what you’re getting at here, and unless you’re playing with the skins somewhere your GUI.Button should be drawing something - it shouldn’t be “invisible” unless you’ve made it that way.

Anyhow, point is that the better you understand your tool the more you can do with them. :slight_smile:

:smile: