首页 > 解决方案 > 如何在 Unity 中仅更改单个字母的颜色?

问题描述

我正在尝试制作纸牌游戏,我想显示一个描述纸牌的文字。说:“对目标造成 4 点伤害。” 我希望这个“4”部分的颜色不同。我怎样才能做到这一点?

public string formerPartOfText = "Deal ";
public int damage = 4;
public string rearerPartOfText = " damages to the target.";

public string finalText = formerPartOfText + damage.ToString + rearerPartOfText;

print(finalText);

我将字符串分成两部分,因为我希望能够更改可变损坏

标签: c#unity3d

解决方案


富文本

特别是颜色标签:

var damage = 4;
var str = $"Deal <color=#ff0000ff>{ damage }</color> damage to the target";

推荐阅读