using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Anim_SequenceFrame : MonoBehaviour { public Material material; public int rowNum,//ÐÐ columnNum;//ÁÐ public float fps = 2; float timer = 0; int currentIndex = 0; float xSize, ySize; int texId = Shader.PropertyToID("_MainTex"); private void Awake() { var r = GetComponent(); if (r) { material = r.material; } else { var g = GetComponent(); if (g) material = g.material; } ySize = 1f / rowNum; xSize = 1f / columnNum; material.SetTextureScale(texId, new Vector2(xSize, ySize)); } // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { float time = 1 / fps; timer += Time.deltaTime; if(timer >= time) { currentIndex += 1; currentIndex %= rowNum * columnNum; timer -= time; } int row = currentIndex % columnNum; int column = currentIndex % rowNum; material.SetTextureOffset(texId, new Vector2((column - 1) * xSize, (row - 1) * ySize)); } }