using UnityEngine; using System.Collections; public class UV_Animation : MonoBehaviour { public float _columnCount=1;//行数 public float _rowCount=1;//列数 public int _framePerSecond;//帧速率 float _colIndex=0; float _rowIndex=0; bool _isPlay=false; float myTime=0; // Use this for initialization void Start () { _rowIndex=_rowCount-1; } // Update is called once per frame void Update () { //改变帧速率 myTime+=Time.deltaTime; _colIndex=Mathf.Floor(myTime*(_framePerSecond-1)); //计算行列位置 _colIndex=_colIndex%_columnCount; if(_colIndex!=0){ _isPlay=true; } if(_isPlay){ if(_colIndex==0){ _rowIndex--; Debug.Log("1="+_rowIndex); if(_rowIndex==-1){ _rowIndex=_rowCount-1; } _isPlay=false; } } //改变贴图uv值 renderer.material.mainTextureScale=new Vector2 (1/_columnCount,1/_rowCount); renderer.material.mainTextureOffset=new Vector2(1/_columnCount*_colIndex,1/_rowCount*_rowIndex); } }