c# - 通过十六进制代码设置颜色
问题描述
我正在使用 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
推荐阅读
- intellij-idea - Intellij 使用 JAXB 生成 java 代码返回 xsd 文件
- html - 我无法通过边框工作在我的 div 中获取此文本
- swift - Swift 将按钮动态添加到 UIScrollView 但它不能滚动,为什么?
- java - 为什么我在 Firebase 上注册新用户失败?
- json - 路由没有定义?
- oracle - jdbc的sql脚本中连接用户名/密码@sid的选项是什么
- java - 在 Fragment 中返回后如何通过 URL 更改图像颜色
- r - R ggplot:如何格式化x轴以使第一个标签与后续标签不同
- firefox-addon - 无法与本机消息传递主机 (firefox) 通信
- jquery - 尝试使用 jQuery 预加载网页时出现“TypeError: e is null”