我正在用RGBA值设置textmeshpro的文本颜色。我想用十六进制代码来设置它。我有一个十六进制颜色值数组。如何在Unity中设置?
using UnityEngine.UI;
public TMP_Text textMeshPro;
public string[] colorListHex = { "#FF0000", "#754C24", "#5DA500"};
void Start(){
textMeshPro.color = new Color32 (255, 0, 0, 255); //How do I set it to be colorListHex[0] instead of using rgba?
}
试试这个。。。
Color colorFromHex;
ColorUtility.TryParseHtmlString(colorListHex[0], out colorFromHex);
https://docs.unity3d.com/ScriptReference/ColorUtility.TryParseHtmlString.html