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)

原文地址:https://www.cnblogs.com/luguoshuai/p/9849028.html