I’m trying to parent a GUIText to a GUITexture (basically put a text caption on a button, which I can then turn into a prefab), but I can’t figure out a way to position the text consistently relative to the button (and there’s no offset, meaning that while I can position the button image using pixel offsets, I can’t move the text with it).
thats strange - im doing the same thing and it works fine.
The best way ive found to manage hierarchical GUI elements in Unity is to set them all to (0,0) pixel offsets and then just adjust the position.
I guess you already know, but pixel offsets are not inherited from parents (postion is), they are always related to the screen (which isnt always the case in other 3D engines, i found the hard way)
also make sure the scale of the GUItexture is (x0,y0,z0) as its caused me problems in the past.
Cheers
Shaun
Does the parent have zero scale? That’ll nullify the local position of children. You’ll have to use pixel positioning on the child.
(Yeah, GUIs… it’s kind of a dark cloud in the Unityverse
But still workable with some elbow grease.)
hmm, we might be confusing you here ![]()
to correctly do GUI parenting in Unity, what has worked for me is the following;
-
create the parent GUITexture (usually a panel or background)
-
set its positon to x0.5y0.5z1 (z value depends on what other gui objects u have in your scene)
-
make sure its rotation and scale values are all 0
-
if the guitexture is 512x64 for example; set the pixel inset to xMin= -256, yMin= -32, xMax= 256, yMax= 32
-
create your child GUI objects inside the parent, make sure position, rotation and scale are all 0 EXCEPT the Z position, which should be higher than the parent)
-
Use the pixel inset to set the correct position relevant to the parent (I highly recommend the NudgeGUI editor script in the wiki for this).
The image below shows a reasonable GUI ive done using this method (all the icons and buttons work, can glow, toggle etc - the checkbox and text boxes also work nicely and all are linked to their respective parents and reposition perfectly on screen resize.
Cheers
Shaun
Aha! Many thanks for your help!
Awesome job btw – Shaunis. Gorgeous and understated.
thanks ![]()
ive got a nice C# class for handling generic GUI objects like buttons, textboxes, checkboxes and radiobuttons etc - I will try to post on the Wiki (i think the code might need some polishing though)
Shaun
Nice interface Shaun!
Well I was going to make one too, but since you already have one… just post it, I don’t mind polishing ![]()
warning - this is what i am actually in the middle of working on now. I’m almost finished the Textfield class (another script) which handles all GUIText stuff and also interacts with the GenericGUIMethods.
Dont flame me if you have problems - just ask. I will post an updated version in the next 2 days when ive had a chance to make it cleaner.
ok here goes ![]()
*EDIT (removed outdated code)
Please check out the Wiki article at:
Wow that was fast :shock:
Thanks, I’ll play with it tonight and maybe do some scrubbing, haha.
nice. ![]()
I get very sleepy while working on GUI code and I’ve been putting it off so you’ve got one grateful guy right here.
great if u guys can make some use of it. let me know if you have some good updates.
like i said, im doing the text input processing routines now, so expect an update -very- soon ![]()
Hehe Last week I lost about an afternoon figuring what was wrong before I realized that the problem was the scale! ![]()
wow shaun - you rock! thanks for posting…
This is really helpful very cool. Thanks Shaun. ![]()
A little tip for those of you grabbing the code from the Wiki and pasting it into Dreamweaver and then wondering why you get a parse error – turn on “show hidden characters” and run a regex to purge the funny spaces – this had me stumped for a while.
(Maybe nobody else but me uses DW to cut code, but it’s handy for me as it’s always open anyway…)
cheers…
