先上图,就是如下这种效果:
GIF录制效果并不是太好,但大概就是这个意思。
以下是实现:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class breath_color : MonoBehaviour {
private Text text_;
private float offset_ = 0.01f;
private int sign_ = 1;
// Use this for initialization
void Start () {
text_ = GetComponent<Text>();
}
// Update is called once per frame
void Update () {
text_.color = ColorBreath(Color.yellow);
}
/// <summary>
/// 类似呼吸灯的效果,让颜色的alpha分量分别在一定范围内来回变化
/// </summary>
/// <param name="col">基础颜色</param>
/// <returns>根据时间变化后的颜色</returns>
private Color ColorBreath(Color col)
{
// 用rgb颜色变化的方法,效果不太行

这篇博客介绍了如何在Unity的UGUI中创建文字颜色的呼吸灯效果。作者探讨了通过改变RGB分量和使用alpha值来模拟亮度变化的方法,最终通过调整alpha值在0.5到1.0之间实现理想的呼吸灯效果。

4373

被折叠的 条评论
为什么被折叠?



