1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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<Renderer>().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<Renderer>().enabled = false;
- overTime = GameTime.time;
- }
- }
- }
- }
- }
|