切割贴图并按帧数进行变换
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetTextureUVST : MonoBehaviour {
public int width;
public int height;
//帧频率
public int fps;
private int currentIndex;
IEnumerator Start()
{
Material mat = GetComponent<Renderer>().material;
//动态改变宽度和高度
float scale_x = 1.0f / width;
float scale_y = 1.0f / height;
while (true){
float offset_x = currentIndex/width*scale_x;
float offset_y = currentIndex%width * scale_y;
mat.SetTextureOffset("_MainTex",new Vector2(offset_x,offset_y));
mat.SetTextureScale("_MainTex",new Vector2(scale_x,scale_y));
yield return new WaitForSeconds(1.0f/fps);
//不会超过边界
currentIndex=(++currentIndex)%(width*height);
}
}
void Update()
{
}
}