Hi there! I’ve been running in circles all morning so I guess it’s time to get help…
I need to have a full-screen transparent texture on top of some GUI elements (buttons etc).
It appears that an old GUITexture is always behind a GUI 2.0 element, so I need my texture to be a 2.0 element too. Why not.
So I’m using GUI.depth to layer my elements, and it works fine. But now my texture cannot grow larger that its actual size, even though I checked “stretch width” and “stretch height” in my GUISkin.
So… does anyone know a way to make an GUI2 image larger than its size?
As a side note, I had a hard time finding GUI.depth because it isn’t called z-index as is common, but it was worth it because I had the overwhelming pleasure to discover it’s ordered in reverse from the old GUI system that used position.z (which was, again, the common order: bigger numbers go in front)… nice one UT :P.
Oh, second one, GUI skins have “stretch width / height” properties, while script-side it’s called GUILayout.ExpandWidth / Height()…
Are you adding the texture (i.e. like an icon) to a GUI Box? If so, I believe that the size should always be the same of the texture. The only way that I think you could use to make it bigger could be to scale the GUI.matrix (BTW, if you want to change the matrix, use GUI.matrix = Matrix4x4.TRS(…) and not GUI.matrix.SetTRS(…), since Matrix4x4 is a struct and this will not work! Took me a bit of a time to figure that one out…).
But why don’t you create a Box with a different style? Change the Box’s default texture to the texture that you want to use.
Actually I just found out that setting style.normal.background instead of GUIContent.image does stretch the texture to the size of the element, so yay, problem fixed!
This works for any element, button, label, box, just put all borders to 0.
I’m afraid I didn’t get the Matrix thing but if someday I have another need I’ll think about it !
For the record, I used a GUI.Label (since there’s no GUI.Image… with no padding by default or something… that would have been nice), with a custom style to display ImageOnly.
GUI.Box(myImage) behaves the exact same way.
Also you say that “the size should always be the same of the texture”… nop, it’s actually scaled down automatically if the element is smaller, that’s why I found it weird that it’s not scaled up…
I’ve even seen a post saying “what if I don’t want it scaled down?”. I add: what if I want it stretched, or tiled?
Well, that’s good to hear, every time I want to just-draw-a-texture-dammit, my finger slips and tries GUI.Image() but Intellisense stubbornly refuses to find it !
Will there be stretch/tile etc options? Tiling would be so neat… I’ve sent a request about it, case #16432.
JustDrawTextureGoddammit sounds like a great idea.
Do you have any tips on how to achieve the same result with the current version of Unity?
I would like to simply draw a texture on top of everything so it fills the whole screen. It’s ok if the texture gets stretched to match the screen coordinates.
I’m a Unity beginner. Isn’t there something in GUI that allows to simply cover the whole screen?
GUIStyleState.background is a Texture2D for whatever reason. I thought you were referring to your earlier code that uses GUI.Box(). GUI.Box takes a Texture. (As do I think all the GUI and GUILayout methods.) Could you use those?
I mean: the image displays correctly. But despite of that, I get an error message that says “Error assigning 2D rectangle texture to 2D texture property ‘_MainTex’: Dimensions must match”. Should I ignore the error message? Or is there something I need to change or add?
Well… I’d say it expects a square texture are your RenderTexture isn’t square… so changing your camera aspect ratio or something should rid you of the warning.
BTW, sorry to barge in on the discussion, I still get topic updates in my mail but I didn’t follow thoroughly ;), so I hope I’m not way off.
Go to your cam > “normalized view port rect”.
The aspect ratio is width/height (or the contrary, I can never remember), but that’s relative to the screen.
You want it to be square (1:1), if I got the error message right.
Now most likely your screen will either be 16:10 or 4:3 (or maybe 32:10 if you’re a millionaire and you own a curved Alienware screen, but let’s say it’s 4:3 to simplify).
So if your cam occupies 1:1 of the screen, its aspect will be 4:3.
So… set height to 1 and width to .75 (= 1/4:3, or 3/4), and bam, you’ve got yourself a square cam.
Now of course you’d have to script it to cover every possible resolution/ratios. And also maybe you don’t want your texture to be square, in which case you’re boned from the start.
I could also be talking nonsense from the start, as I’m only interpreting from the error message you gave but never played with RenderTextures myself… who knows?