- Home /
Image Sequence Loop
I've got an Image Sequence where I want to play the first part once then loop the second part. I've got the sequences in separate folders in the Resource folder of my project (First part in one folder, looped part in another). I have then put the following script on a Quad:
using UnityEngine;
using System.Collections;
public class ImageSequence : MonoBehaviour {
private Object[] objects;
private Object[] otherObjects;
private Texture[] textures;
private Texture[] otherTextures;
private Material goMaterial;
private int frameCounter = 0;
void Awake(){
this.goMaterial = this.GetComponent<Renderer> ().material;
}
void Start () {
this.objects = Resources.LoadAll ("Sequence", typeof(Texture));
this.otherObjects = Resources.LoadAll ("SequenceLoop", typeof(Texture));
this.otherTextures = new Texture[otherObjects.Length];
this.textures = new Texture[objects.Length];
for (int i=0; i<objects.Length; i++) {
this.textures [i] = (Texture)this.objects [i];
}
for (int i=0; i<otherObjects.Length; i++){
this.otherTextures [i] = (Texture)this.otherObjects [i];
}
}
void Update () {
StartCoroutine ("Play", 0.04f);
goMaterial.mainTexture = textures [frameCounter];
}
IEnumerator Play (float delay){
yield return new WaitForSeconds (delay);
if (frameCounter < textures.Length - 1) {
++frameCounter;
}
StopCoroutine ("Play");
StartCoroutine ("PlayLoop", 0.04f);
}
IEnumerator PlayLoop(float delay){
yield return new WaitForSeconds (delay);
frameCounter = (++frameCounter) % otherTextures.Length;
StopCoroutine ("PlayLoop");
}
}
However, this script will loop the first part and nothing of the second part. I'm sure I'm just getting things mixed up and theres a simple enough solution for it. Can anyone shed some light?
Comment