- Home /
Load level after Image Sequence
I have a image sequence array made of .pngs that plays at the opening of a scene. After that image sequence stops I would like to load a new level only I'm having trouble doing that. I would like to know how I can modify my code to make that possible. Seems easy but i just can't get it right here is the code I'm working with.
using UnityEngine; using System.Collections;
public class ImageSequenceTextureArray : MonoBehaviour {
private Object[] objects;
private Texture[] textures;
private Material goMaterial;
private int frameCounter = 0;
void Awake()
{
//Get a reference to the Material of the game object this script is attached to
this.goMaterial = this.renderer.material;
}
void Start ()
{
this.objects = Resources.LoadAll("Sequence", typeof(Texture));
this.textures = new Texture[objects.Length];
for(int i=0; i<objects.Length;i++)
{
this.textures[i] = (Texture)this.objects[i];
}
}
void Update ()
{
StartCoroutine("Play",0.60f);
goMaterial.mainTexture = textures[frameCounter];
}
IEnumerator PlayLoop(float delay)
{
yield return new WaitForSeconds(delay);
frameCounter = (++frameCounter)%textures.Length;
StopCoroutine("Play");
}
IEnumerator Play(float delay)
{
yield return new WaitForSeconds(delay);
if(frameCounter < textures.Length-1)
{
++frameCounter;
}
StopCoroutine("Play");
}
}
You really want to call that Coroutine in the Update() function??
Answer by moriam · Mar 30, 2015 at 01:44 PM
You can add an else statement where you increment the frame counter:
IEnumerator Play(float delay)
{
yield return new WaitForSeconds(delay);
if(frameCounter < textures.Length-1)
{
++frameCounter;
}
else
{
Application.LoadLevel("Your Scene");
}
StopCoroutine("Play");
}
thanks @moriam i was adding my else to the wrong function, thanks for the help very cool!
Your answer
Follow this Question
Related Questions
How the scene works 1 Answer
Multiple Instances of My Current Scene? 0 Answers
Current scene number 2 Answers
How can I save the player's progress in-game? 1 Answer
What is the Difference betwwen a "Level" and a "scene" 2 Answers