本篇文章讲述使用代码改变
NGUI的Label的Tween的Style
NGUI的Label的Tween Color的改变的颜色
使用代码控制NGUI的Label改变颜色有两种方法
1.直接在NGUI的Label的Text里面输入颜色RGB代码
点击Color Tint的Hex Color 就是对应RGBA,A是Alpha值
2.通过代码改变
如下所示,通过代码改变text也是可以实现的
R = 255 /255;
G = 255 / 255;
B = 255 / 255;
A = 255 / 255;
//this.GetComponent<UILabel>().text = "[99ff66]Strength";
this.GetComponent<UILabel>().color =new Color(R, G, B, A);
NGUI的UI的Label怎么实现颜色的渐变
NGUI---Tween---Color,如果是固定的就直接添加组件,进行设置就行了
如果想使用代码动态设置,可以把Tween Color右键Edit Script打开,就可以设置相对应的属性
一步一步查表可以得到NGUI的Label的Tween的Style的设置如下所示
gameObject.GetComponent<TweenColor>().style = UITweener.Style.PingPong;
gameObject.GetComponent<TweenColor>().style = UITweener.Style.Once;
gameObject.GetComponent<TweenColor>().style = UITweener.Style.Loop;
PingPong从From值到To,从To 到From不停变化
Once从From值到To,变化一次
PingPong从From值到To,不停变化
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LabelChangeColor : MonoBehaviour {
private float R;
private float G;
private float B;
private float A;
// Use this for initialization
void Start () {
R = 1 /255;
G = 1 / 255;
B = 1 / 255;
A = 1 / 255;
//this.GetComponent<UILabel>().text = "[99ff66]Strength";
//this.GetComponent<UILabel>().color =new Color(R, G, B, A);
if (!gameObject.GetComponent<TweenColor>())
{
gameObject.AddComponent<TweenColor> ().from = new Color(R, G, B, A);
gameObject.GetComponent<TweenColor>().to = new Color(1, 1, 1, 1);
gameObject.GetComponent<TweenColor>().style = UITweener.Style.PingPong;
}
}
public void LabelChangeColorRGBA(float r,float g,float b,float a)
{
R = r;
G = g;
B = b;
A = a;
this.GetComponent<UILabel>().color = new Color(R, G, B, A);
}
}
duration意思是延迟,使用方法gameObject.GetComponent<TweenColor>().delay = 2f;//延迟2S
参考文章:
1.NGUI设置UIButton的颜色值影响子UISprite.color值
2.[3D理论]Unity3D NGUI的label怎么键入不同颜色的字体
4.unity开发 --------- NGUI (UIButtonColor、TweenColor、Light)

本文介绍了如何在Unity中使用NGUI组件动态改变Label的颜色,包括直接通过RGB代码设置和通过代码控制。同时,讲解了如何实现Label颜色的渐变效果,详细阐述了TweenColor的Style设置,如PingPong、Once和Loop,并提供了实现颜色渐变的代码示例。
1613

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



