Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Created November 20, 2014 01:16
Show Gist options
  • Save paulhayes/db82aeea3cd6495811a3 to your computer and use it in GitHub Desktop.
Save paulhayes/db82aeea3cd6495811a3 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class SimpleFramePlayer : MonoBehaviour {
public float fps;
public Texture[] frames;
private float spf;
private float timeElapsed;
private int currentFrame;
void Start () {
spf = 1f/fps;
}
void Update () {
timeElapsed += Time.deltaTime;
if( timeElapsed >= spf ){
timeElapsed -=spf;
currentFrame = ( currentFrame + 1 ) % frames.Length;
}
renderer.sharedMaterial.mainTexture = frames[currentFrame];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment