using UnityEngine; using System.Collections; public class PlaneAnimation : MonoBehaviour { public float frameRate = 30f; public float currentFrame = 0; public bool loop; public Texture[] textures; private float startTime; private float duration; private bool endFristTime = false; public bool removeWhenEnd = false; // Use this for initialization void Start () { startTime = GameTime.time; duration = textures.Length / frameRate; } // Update is called once per frame void FixedUpdate () { float oldFrame = currentFrame; float offset = (GameTime.time - startTime) % duration; currentFrame = Mathf.Floor(textures.Length * offset / duration); if (loop) { GetComponent().material.mainTexture = textures [(int)currentFrame]; } else { if(!endFristTime) { if (currentFrame < oldFrame) { endFristTime = true; if(removeWhenEnd) { Destroy(this.gameObject); } } else { GetComponent().material.mainTexture = textures [(int)currentFrame]; } } } } }