3
\$\begingroup\$

I am doing a 2D casual puzzle where the user can drag and drop some pieces into a board. The pieces are 2 or 3 or 4 tiles. Each tile may have text over the sprite.

Target platform: Mobiles and tablets.

I wonder if the right approach is to use 2D sprites or to use UI images for displaying the board, the tiles and the pieces on it.

On one side, doing all the game based on UI elements seem weird. On the other side, if I do it based on sprites, how do I attach texts on the sprite?

Which approach should I pick?

\$\endgroup\$
2
\$\begingroup\$

In my experience these are the two most important differences between Sprites and UI Images: 1. Images need to be inside a UI Canvas and they use a RectTransform instead of the regular transform. This means they can use the new anchor/pivot features and their positions will be in pixels instead of units. 2. It's more convenient to handle clicks and other mouse events using EventTrigger

I usually prefer to make a distinction between UI elements and gameplay stuff so in your case I would probably use Sprites for the gameplay elements. Adding text is easy but you need to know how :) You can add a Canvas as child of the sprites, configure it to live in "world space" and then scale it down to fit in the dimensions you want.

There are multiple posts in the Unity forums explaining how to do this but ask if you can't figure it out.

\$\endgroup\$
  • \$\begingroup\$ dyego's answer explains "Adding text is easy but you need to know how" \$\endgroup\$ – jhocking Oct 9 '15 at 3:02
0
\$\begingroup\$

Well in UI, you can use more stuff to help you. For example, grid layout which helps you align all the pieces in grid automaticly. Also handling mouse events is way easier with ui elements, eg for drag and drop there are events for that.

There is also option to use UI inside world space..

Ps: im writing this answer on mobile. I can provide more info later on.

\$\endgroup\$
  • 1
    \$\begingroup\$ Pity you never provided more info. \$\endgroup\$ – Engineer Oct 13 '16 at 17:51
0
\$\begingroup\$

I think it's simple!

Just use TextMesh and draw it over the Sprite. It's in the Component menu at: Mesh > Text Mesh

\$\endgroup\$
  • \$\begingroup\$ this isn't a full answer unto itself, but rather a useful addition to miguel's answer \$\endgroup\$ – jhocking Oct 9 '15 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.