ArgumentOutOfRangeException

Hi, i´ve been looking for a way to show a video in unity. Since i don`t have unity pro, i searched for an alternative to Movie/Render-Textures etc… I then found this script on the internet:

    #pragma strict
    var imageFolderName = "";
    var MakeTexture = false;
    var pictures = new Array();
    var loop = false;
    var counter = 0;
    var Film = true;
    var PictureRateInSeconds:float = 1;
    private var nextPic:float = 0;
     
    function Start () {
    if(Film == true){
    PictureRateInSeconds = 0.04166666666666666666;
    }
     
    var textures : Object[] = Resources.LoadAll(imageFolderName);
    for(var i = 0; i < textures.Length; i++){
    Debug.Log("found");
    pictures.Add(textures*);*

}
}

function Update () {
if(Time.time > nextPic){
nextPic = Time.time + PictureRateInSeconds;
counter += 1;
if(MakeTexture){
renderer.material.mainTexture = pictures[counter];
}
}
if(counter >= pictures.length){
Debug.Log(“fertig”);
if(loop){
counter = 0;
}
}
}
Basically, what it does is let you display all images in a folder “x” in a short time on an object and so create a video effect. I tested the script and it worked really good, until it reached the end of the clip. The Game crashed and Unity showed me this error: “ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.”
I´m not very experienced with scripting, so i would be thankfull for any suggestions on where the mistake could be :slight_smile:

At first glance, it looks like the logic for looping the counter is run (or, at least, performed at the wrong time. Try replacing the Update function with this (untested):

function Update () {
  if(Time.time > nextPic){
    nextPic = Time.time + PictureRateInSeconds;

    // If we're not yet on the last frame
    if(counter < pictures.length - 1){
      // Advance to the next frame
      counter += 1;
    }
    // If we're already on the last frame
    else {
      // If we're meant to loop
      if(loop){
        // Go back to the first frame
        counter = 0;
      }
    }
    // Load the appropriate frame texture
    if(MakeTexture){
      renderer.material.mainTexture = pictures[counter];
    }
  }
}

thanks a lot, it works perfectly now.