首页 > 其他 > 详细

NGUI实现UITexture的UV滚动

时间:2018-10-25 13:19:43      阅读:246      评论:0      收藏:0      [点我收藏+]

材质上使用的贴图:

技术分享图片

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

代码:

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!