一、前言今天介绍一些非常简单的东西。 就是用代码改变文本字体的颜色。 那么,我来介绍一下为什么很简单。
因为今天突然被问了这个问题,所以我以不想陷害人的原则去了百度,但是没能回答出想法
所以,写一篇新文章,介绍如何实现。
二、改变字体颜色即成一行代码:
using System.Collections; using system.collections.generic; 用户单元引擎; using UnityEngine.UI; publicclasstextcolorchange : mono behaviour { public texttext; void start ((text.color=color.white; 获取文本的color属性,直接更改值即可。
那么,同学问如果想输入RGB的值该怎么办:
例如,您的RGB值为129 69 69 255 :
using System.Collections; using system.collections.generic; 用户单元引擎; using UnityEngine.UI; publicclasstextcolorchange : mono behaviour { public texttext; voidstart((text.color=newcolor ) 129/255f、69/255f、69/255f、255/255f ); }就可以了。
另外,也有同学认为用十六进制换颜色可以吗?
using System.Collections; using system.collections.generic; 用户单元引擎; using UnityEngine.UI; publicclasstextcolorchange : mono behaviour { public texttext; void start ((color utility.tryparsehtmlstring ) )、out Color nowColor ); text.color=nowColor; }就可以了。
三.在文本中输入改变字体颜色的代码,可以在文本中输入改变字体颜色的代码来改变颜色。 例如:
using System.Collections; using system.collections.generic; 用户单元引擎; using UnityEngine.UI; publicclasstextcolorchange : mono behaviour { public texttext; void start ((text.text=' color=# 0000 ff字体颜色/color ) ); }} RGB颜色查询: