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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值