1
\$\begingroup\$

I'm creating a component that lets you write text, like the UI Text component, but using sprites as letters.

I already have the mapping for characters->sprites, and now was going to draw the text using the sprites.

My first idea, was to just create one children for each letter, each child having a sprite renderer.

But it feels like a pretty poor approach, since a transform and a sprite renderer component have to created or destroyed, when the text changes size.

Then I thought about using a Mesh renderer and mesh filter, and define the mesh when the text changes, creating a quad for each letter. But what I don't like about this idea is having 2 extra components in my gameObject, as I would like to keep it as clean as possible.

Is there a way to achieve this keeping all the necessary components inside my own class? Defining my own quads, UVs and such is just fine, but I just don't know how to render them through script. Is it even possible without adding more components to the gameObject?

Don't know if its relevant, but I want to use World Coordinates, not screen coordinates.

\$\endgroup\$
  • \$\begingroup\$ Don't be afraid of components. As a component-based engine, Unity is made to manage lots of components with decent efficiency. If you can do what you want out of the box with a combination of existing components, nine times out of ten that's a good way to do it, and will let you get up & running fast, freeing you up for more iteration, polish, and all the other hard problems your game needs to solve. Tailoring SpriteRenderers, a custom Mesh, or a ParticleSystem to render these letters for you is very likely to be less work than hand-coding it all, and still plenty efficient for your needs. \$\endgroup\$ – DMGregory Aug 4 '17 at 13:16
-1
\$\begingroup\$

Your first approach was an effective way! Though I can't show code right now, you need to change the sprite for each space(in your code) to form your words. Also, if you can figure out how to do it right, you could make a font and use text instead.

\$\endgroup\$

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.