x


GUILayout.Box controlling Width

I want to control the width of a GUILayout Texture2D.

GUILayout.Box(fuelBarTex, fuelBarStyle);

I tried to do this by GUILayout.Width;

GUILayout.Box(fuelBarTex, fuelBarStyle, GUILayout.Width(100));

But this also scales the hight even when i give a absolute hight with it.

GUILayout.Box(fuelBarTex, fuelBarStyle, GUILayout.Width(100), GUILayout.Height(100));

So maybe this can be done, but for some reason it's not.

i also tried this:

   var fuelBar: GUILayout;
   fuelBar =  GUILayout.Box(fuelBarTex, fuelBarStyle);
   fuelBar.width = 200;

that doesnt work either.

I cannot use GUI.Box because i want it to be in the top-left part of the screen, even if resized. can someone explain me what i'm doing worng?? Thanks

more ▼

asked Sep 17 '10 at 01:50 PM

nahkranoth gravatar image

nahkranoth
3 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can still use GUI.Box (or GUI.DrawTexture would be better) and have it scale to the screen resolution. Just do this:

function OnGUI(){
   GUI.DrawTexture(Rect(Screen.width*0.1,Screen.height*0.1,100,100),fuelBarTex);
}

This way the texture will always be 10% of the screen width across. You can use any kind of equation you want with Screen.width if that's not where you want it.

If you wanted it flush with the corner then it'd be Rect(0,0,100,100)

more ▼

answered Sep 17 '10 at 04:46 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x137
x35

asked: Sep 17 '10 at 01:50 PM

Seen: 1373 times

Last Updated: Sep 17 '10 at 01:50 PM