- Home /
Display Emojis using its HTML code in a text
Hi!
I was wondering if there is a way to display Emojis in a text using its HTML code (for example, bicycleEmojiCode string is the bicycle emoji in HTML). All I've found uses unicode or other code rather than HTML. This is the code I'm using right now:
private Text textWithEmoji;
private const string biclycleEmojiCode = "🚴";
private void Awake()
{
textWithEmoji = GetComponent<Text>();
}
private void Start ()
{
textWithEmoji.text = biclycleEmojiCode;
}
Why would you want HT$$anonymous$$L codes anyway? I believe you have no choice but create a map (dictionary) HT$$anonymous$$L → unicode.
Answer by Bunny83 · Nov 09, 2019 at 10:25 PM
🚴
is not an HTML "code". It's actual a SGML / XML / HTML entity reference. Such an entity generally has the form of &XXXX;
where XXXX represents the entity name. The special character #
denotes a unicode character and the following numbers are simply the decimal unicode code point for the character. Instead of a decimal code point it's usually more common to use hexadecimal code points. For this you generally use &#xHHHH;
in XML / HTML where HHHH is a hexadecimal number.
Of course HTML or anything related to HTML is completely irrelevant in Unity. If your used font actually supports your wanted code points you can simply use those unicode characters directly inside your code by using the proper C# unicode escape sequences. In C# you can only specify hexadecimal unicode code points. There are two ways. Either \uXXXX
or \UXXXXXXXX
Note that when using \u
you always have to give exactly 4 hex digits when using \U
you have to specify exactly 8 digits. So \u
can only be used for the code points 0000 to FFFF.
The code point in question () is beyond the four digits so you have to use \U
. The decimal number "128692" is "1F6B4" in hexadecimal. Since we need 8 digits we have to add 3 padding zeros:
public const string biclycleEmoji ="\U0001F6B4";
Hi @Bunny83 thanks for the answers, I really appreciate it. I've tried using \U0001F6B4 but it always show a ? mark inside a diamond. Do you know how to solve that issue? I've Rich Text enabled and have tried different fonts that are supposed to support emoji, but doesn't seem to work :(
Your answer
Follow this Question
Related Questions
UI components all disappear on Play mode, then stay invisible 2 Answers
TextMesh Pro Page content 2 Answers
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
How to find position of sprites generated by tag in TextMesh Pro? 0 Answers
Is it possible to check tag for certain components and then change Text? 1 Answer