NGUI实现UITexture的UV滚动

Posted luguoshuai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NGUI实现UITexture的UV滚动相关的知识,希望对你有一定的参考价值。

材质上使用的贴图:

技术分享图片

效果:实现该纹理在屏幕上的滚动

代码:

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class NewBehaviourScript : MonoBehaviour
 6 {
 7     [SerializeField]
 8     float USpeed;
 9     [SerializeField]
10     float VSpeed;
11 
12     UITexture tex;
13 
14     void Start()
15     {
16         if (null == tex)
17             tex = gameObject.GetComponent<UITexture>();
18     }
19 
20     void Update()
21     {
22         float newOffsetU = USpeed * Time.time;
23         float newOffsetV = VSpeed * Time.time;
24 
25         if (null != tex)
26         {
27             tex.enabled = false;
28             tex.material.mainTextureOffset = new Vector2(newOffsetU, newOffsetV);
29             tex.enabled = true;
30         }
31     }
32 }

需要注意:纹理的寻址模式应该设置为 重复寻址模式(Repeat)

以上是关于NGUI实现UITexture的UV滚动的主要内容,如果未能解决你的问题,请参考以下文章

使用自定义材质球,实现NGUI屏幕溶解和灰显

NGUI_Texture

[Shader]对NGUI的UISprite和UITexture进行裁剪

Unity3DNGUIAtlas的动态创建

Unity编辑器:基于NGUI的引用检测工具

unity rendertexture 怎么创建