Drawing rectangles around UI Text

Hi folks. I hope this is simple

I’ve been looking through the docs. I’ve been wanting to draw rectangles around the bowling scores. I could just load an image and map it behind the text, but I’d rather have something crisper, like a line draw.

I could write a c# routine that would draw lines (make it a subroutine, called from each Score Frame 0X object), but it seems like there should be some kind of ‘rectangle’ primitive object I could just layer onto the UI, via the normal game components, instead of code.

I looked all over the docs, and keep getting code samples using something like:
GUI.Box( position, GUIContent.none, _staticRectStyle );

I’m a programmer, so to me, everything is code, but doing visual layouts is much nicer.

I also saw “Outline” but that seems to draw an outline around the TEXT, not the square that’s defined. I tried messing with buttons but that didn’t seem straight forward.

What’s the best way to do this? Thanks!

== John ==

Buttons seem the best option to me. By turning off “Fill Center” on the Button Image component, you’ll get an outline. It’s still image based rather than vector based, but it’s convenient and it has a child Text for displaying the score.

The “rectangle” component is a Panel, but if it were me I’d probably go the Button approach.

LOL Love the “Hi John” … thanks!

Ah, so your UISprite is a square. Got it.

It occurs to me we have to update the scores all the time anyway, I could also just draw the square when the score is updated. Might look nice to see the squares march across the display, but you’re right, the button is more convinient.

== John ==

1 Like