10
\$\begingroup\$

How can I use different materials when using the tag for Unity's rich text syntax?

I want to be able to have sprites that are inline with my text without having to create custom fonts.

Here's what I have so far: enter image description here Here's the syntax that I'm using for the text in my image:

Planetary <quad material=1 size=20 x=0.1 y=0.1 width=0.1 height=0.1 /> Intergalactic

I'm guessing "material=1" refers to the material index of the Text object. How can I set it to use a different material altogether?

Is there a plugin or other resource that makes embedding icons in text easier?

\$\endgroup\$
  • 3
    \$\begingroup\$ Using a quad with Unity's rich text is the only way to go. The material attribute is the material at the "position in the renderer’s material array". I would preprocess or concat in the proper material index by looking through Renderer.materials to find the material you are after. \$\endgroup\$ – MLM May 22 '15 at 5:57
  • \$\begingroup\$ I'll give that a shot and get back with some results, thanks MLM! \$\endgroup\$ – James Linden May 22 '15 at 15:48
  • 1
    \$\begingroup\$ This question is cross-posted on Unity Answers. It seems that while rich text is supported, quads are not according to Tim C and Phil from Unity, see: forum.unity3d.com/threads/… \$\endgroup\$ – MLM May 22 '15 at 20:27
  • 1
    \$\begingroup\$ I've made an implementation that does this in UI Text (as opposed to the quad method with TextMesh) by dynamically spawning & positioning child images. The details get a little complicated, but if it's useful to anyone I can write it up as an answer. \$\endgroup\$ – DMGregory Jan 19 '16 at 19:21
  • \$\begingroup\$ @DMGregor, I'd love to have you write up an answer or link to your code for your Sprited Image script. \$\endgroup\$ – James McMahon Apr 28 '16 at 21:43
1
\$\begingroup\$

As the text system is still the legacy text system, you can't embed images in text. Only option would be to have a layout group and have separate text and image blocks

Alternatively, you can use an asset like TextMeshPro which has a new text implementation which supports this fully (and much more!)

\$\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.