For the love of god making a gui should not be this complicated…Admittedly I’m relatively new to unity but have been digesting tutorials and pouring through videos and the manual but I cannot get my head around the gui system.
I have several interface images I want to paste to the screen and I want to use standard x,y, coordinates to position them or have the ability to offset them dynamically using screen width/ screen height.
Gui texture has a retarded positioning system of 0 to 1 and the onGui command allows me to paste an image into a container with a semi transparent rounded rect…this solves my problem of wanting to position gui elements using standard XY coords but how do I get rid of the semi transparent rounded rect…
I am EXTREMELY frustrated after several hours of trying to figure this out… it CANT be this hard…
any help is greatly appreciated.
That “retarded” system allows you to make resolution-independent UI graphics that automatically work on any screen size with zero extra work.
There are many OnGUI commands. Which one are you using?
Use an appropriate GUIStyle or GUI skin.
–Eric
I just want to position elements to the screen Im not really interested in them scaling.
After reading about Guiskins styles I go to assets and add a new Guiskin element…I have gone through the drop downs and roll-outs setting all the backgrounds to “none” apparently Im missing something because they are still showing up.
/* GUI.Button example */
var icon : Texture2D;
function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Top-left");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-right");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width/2 - 50,Screen.height/2 - 50,100,50), "center-screen");
GUI.Box (Rect (200,200,230,86), GUIContent(icon));
}
Eric’s comments are correct for GUITextures. You may want to look at the GUI.DrawTexture function, though – that seems to be closer to what you are trying to accomplish.
If I am misinterpreting your question, just show us a little more code…
thanks for pointing me in the right direction…
the following code worked as expected.
var icon : Texture2D;
var myskin : GUISkin ;
function OnGUI () {
GUI.skin = myskin;
GUI.DrawTexture(new Rect(0,0,250,90), icon);
}
Still, I couldn’t find any references in the manual to the DrawTexture command…I could only find examples in the forum posts to follow, Where is the documentation located? THe manual doesnt seem to have a keyword search(or any search function).
Unity’s website > Support > Documentation.
The scripting reference (searchable) is here.
You may also adjust the position of a GUITexture element in a ‘pixel-perfect’ manner by setting the scale vector of its transform to zero and setting the pixelInset field to whatever area you want the texture to be displayed within.
Ahh thank you very much…I really wasnt understanding what the pixel inset was for…
In relation to pixel perfect settings.
I’m creating a game that is purely 2d using GUI Textures… Should I be using transforms, or pixels to position them on screen?
I’ve been using pixel inset, but wanted to make sure this was the best method.
Cheers
Transforms are less intuitive in 2D but let you position the object in a resolution–aspect-ratio-independent way whereas you would have to compute conversions on the coordinates if you are using the pixel inset rectangle.
By the way, remember that you cannot rotate GUITexture objects. If you need the feature you might want to start looking for alternatives now (native textured quads or UnityGUI).