using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using static System.Net.Mime.MediaTypeNames;
using System.Xml.Linq;
public class tmpcolor : MonoBehaviour
{
public TMP_Text UIText;
private float timer;
void Start()
{
timer = 0.0f;
}
// 通过update获得每帧运算
void Update()
{
timer += Time.deltaTime * 2;
if (timer % 2 > 1.0f)
{
UIText.color = Color.yellow;//文字颜色变黄
}
else
{
UIText.color = Color.white;//文字颜色变白
}
}
}
要注意:public class tmpcolor : MonoBehaviour 中 tmpcolor要和你的脚本名称保持一致
然后把这个代码附加到你需要修改颜色的TMP物体上就可以了
具体方法是:在Hierarchy中点击物体,在右侧点击Add Component,输入tmpcolor并选择,然后将需要操作的TextmeshPro物体从Hierarchy拖到右侧的inspector中text后面的框框内
其他unity相关文章:
其他unity内容: https://www.gongyesheji.org/?cat=860
UNITY如何删除插件(包/packages)
Hololens2+unity实现QRCODE二维码识别
unity如何实现点击按钮后文字改变
通过UNITY中的Textmeshpro(TMPro)UI显示当前系统时间
unity实现点击按钮多次延迟切换背景图片/界面
Unity物体在原位置上下浮动效果的代码
Unity延迟2秒后让TextmeshPro字体变色的脚本