Unity材质贴图滚动效果
程序员文章站
2022-06-11 10:53:14
...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaskMove : MonoBehaviour {
//滚动速度
private float HorSpeed = -1.0f;
private float VerSpeed = 0.0f;
//Offset偏移量
//水平滚动Offset.y
private float HorMin = 1.0f;
private float HorMax = 2.0f;
//垂直滚动Offset.x
private float VerMin = 1.0f;
private float VerMax = 2.0f;
//渲染器
MeshRenderer MeshR;
private void Awake()
{
//获得渲染器
MeshR = GetComponent<MeshRenderer>();
}
private void Update()
{
Vector2 Offset = new Vector2(
(MeshR.material.mainTextureOffset.x > HorMax) ? HorMin : MeshR.material.mainTextureOffset.x + Time.deltaTime * HorSpeed,
(MeshR.material.mainTextureOffset.y > VerMax) ? VerMin : MeshR.material.mainTextureOffset.y + Time.deltaTime * VerSpeed
);
MeshR.material.mainTextureOffset = Offset;
}
}
把这个代码的脚本拖到需要滚动的材质物体上运行就可以了
转自:https://www.cnblogs.com/Prode/p/9999463.html