- Home /
Change GUI Value with Variable
Hey guys. Me again. I made this script a while ago and I can't seem to get the location in the screen right. I am new at scripting and I'm only now starting to get it all down. Can someone review this and tell me what I did wrong? Thanks to anyone who helps.
Cody var labelWidth : int; var labelHeight : int;
function OnGUI () { GUI.Box (Rect (labelWidth.width, labelHeight.height,300,25), "Press the 'm' key to toggle mouse visibility"); // Draws a box with text }
Also I don't know why its coming out all ugly in this question But it is formatted properly. Thanks.
Answer by danielskovli · Mar 04, 2014 at 03:13 AM
Hi,
It looks like you're trying to access .width and .height properties of an int (which most likely does not contain those properties.
Try changing your code to simply Rect(labelWidth, labelHeight, 300, 25);
Keeping in mind that those two positions in the Rect() actually refer to the position for X and Y, not the actual width and height, but I guess that's just a variable naming issues.
Cheers, Daniel
It's actually supposed to be the offset values. But it would be the same thing, right?
Yep, absolutely. $$anonymous$$aybe for your own sanity you could just name them differently - they'll work just fine as they are though :)
If you want to get more fancy and have total control, you could do this:
public Rect yourBox; // Gives you the 4 values to set in the Unity Editor
void OnGUI() { GUI.Box (yourBox, "Press the 'm' key to toggle mouse visibility"); }