NGUI UITexture 设置帧动画闪烁(不显示)问题

发表于2019-01-14
评论0 7k浏览
做项目的时候有时候需要用到帧动画,但有时候帧动画可能不显示,针对这个情况本篇文章主要给大家分享下NGUI UITexture 设置帧动画闪烁(不显示)问题的解决办法。

解决:.enabled = false;
          .enabled = true;

示例代码:
public class TextureAnimation : MonoBehaviour {
	public Texture[] TextureAll;
	private UITexture curtexture;
	public float speed = 0.01f;
	private float timer = 0;
	private int index = 0;
	// Use this for initialization
	void Start () {
		curtexture = GetComponent<UITexture> ();
	}
	// Update is called once per frame
	void Update () {
		play ();
	}
	private void play(){
		if(TextureAll == null | TextureAll.Length<1){
			return;
		}
		timer += Time.deltaTime;
		if (timer > speed) {
			timer = 0;
			if (index < (TextureAll.Length - 1)) {
				index++;
			} else {
				index = 0;
			}
			curtexture.enabled = false;
			curtexture.mainTexture = TextureAll [index];
			curtexture.enabled = true;
		}
	}
	public void reset(){
		timer = 0;
		index = 0;
		curtexture.mainTexture = TextureAll[0];
	}
}

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

标签: