using UnityEngine; using System.Collections; public class TileAnim : MonoBehaviour { public float width; public float height; public float totalWidth; public float totalHeight; private int count; private int cols; private int rows; public int loop = 0; private int currentLoopTime = 0; public float removeDelay = 0; private float overTime = -1f; // Use this for initialization void Start () { count = 0; cols = (int)(totalWidth/width); rows = (int)(totalHeight/height); } // Update is called once per frame void Update () { if(overTime > 0) { if(GameTime.time-overTime>removeDelay) { Destroy(this.gameObject); } return; } int col = count%cols; int row = count/cols; float offsetX = col*width/totalWidth; float offsetY = row*height/totalHeight; GetComponent().material.mainTextureOffset = new Vector2(offsetX, offsetY); count++; if(count >= cols*rows) { count = 0; currentLoopTime++; if(loop >= 0 && currentLoopTime >= loop) { if(removeDelay == 0) { Destroy(this.gameObject); } else { this.GetComponent().enabled = false; overTime = GameTime.time; } } } } }