1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Unity]TextMeshProでの文字毎の色指定

Posted at

備忘

文字毎に色を設定したい
文字列補完式も使って簡単に

1.TextMeshProのタグ指定
 <color="red">や<color=#FF0000>mozi</color>で任意の色が設定可能
2.文字列補完式を用いる。
 {valu:X}で16進数に表記に置き換わる。{16:X}の場合はF1など

<使用例>

Colors.cs
public enum ChatColor : uint
{
    RED = 0xFF0000FF,// 赤
    GRN = 0x00FF00FF,// 緑
    BLR = 0x0000FFFF,// 青
}
Monobehavior.cs
public class Chat : Monobehavior
{
    TMPro.TMP_Text m_Message = default;

    void Awake()
    {
        m_Message.text = $"<color=#{ChatColor.RED:X}>メッセージ</color>";
    }
}

実行時には「<color=#FF0000FF>メッセージ</color>」と
置き換わり赤文字で「メッセージ」と画面上に出力される

Red-Green-Blue-Alpha
・FF-00-00-FF⇒赤色
・FF-00-00-00⇒赤色(でも透明)
・FF-FF-FF-FF⇒黒色
・00-00-00-FF⇒白色
っぽいです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?