123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<Renderer>().material.mainTexture = textures [(int)currentFrame];
- }
- else
- {
- if(!endFristTime)
- {
- if (currentFrame < oldFrame)
- {
- endFristTime = true;
- if(removeWhenEnd)
- {
- Destroy(this.gameObject);
- }
- }
- else
- {
- GetComponent<Renderer>().material.mainTexture = textures [(int)currentFrame];
- }
- }
- }
- }
- }
|