码迷,mamicode.com
首页 > 其他好文 > 详细

NGUI实现UITexture的UV滚动

时间:2018-10-25 14:24:39      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:led   get   fse   class   false   enable   img   重复   lse   

材质上使用的贴图:

技术分享图片

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

代码:

 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滚动

标签:led   get   fse   class   false   enable   img   重复   lse   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!