材质上使用的贴图:
效果:实现该纹理在屏幕上的滚动
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class NewBehaviourScript : MonoBehaviour
{
[SerializeField]
float USpeed;
[SerializeField]
float VSpeed; UITexture tex; void Start()
{
if (null == tex)
tex = gameObject.GetComponent<UITexture>();
} void Update()
{
float newOffsetU = USpeed * Time.time;
float newOffsetV = VSpeed * Time.time; if (null != tex)
{
tex.enabled = false;
tex.material.mainTextureOffset = new Vector2(newOffsetU, newOffsetV);
tex.enabled = true;
}
}
}
需要注意:纹理的寻址模式应该设置为 重复寻址模式(Repeat)