when I tried to load a script (described below and written by arky25 ) , which was supposed to help me make an Image Sequence Texture ,a console error appeared :
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
5
System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Collections/ArrayList.cs:3261)
System.Collections.ArrayList.get_Item (Int32 index) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Collections/ArrayList.cs:2652)
UnityScript.Lang.Array.get_Item (Int32 index)
video.Update () (at Assets/Scripts/video.js:28)
if you want to try the script :
first you have to load your pictures into a folder , put its name in the script then you have to create a Resources folder and put the folder with the pictures into that folder
the script is :
#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*);*
First, this is not your script - You should clearly tell where you got it from, and give credits to the right people.
Second, it would be nice if you pointed out where exactly in the ‘posted’ code - at which line the error is occurring, instead of having us copy the thing and test it out for you.
About your problem, just increment counter after you change material:
pictures is a sequence - it starts indexing from 0 to pictures.Length-1 - getting a IndexOutOfRange exception means that you’re doing something like pictures[n] where n < 0 || n >= picture.Length - You’re incrementing counter, and then using it as an index, and then afterwards, you check to see if counter has gone above or equal to pictures.Length - so when counter == pictures.Length-1 - You increment it, now it’s equal to pictures.Length and then you’re doing pictures[counter] which is equivalent to pictures[pictures.Length] - You’re out of bounds!
Some tips:
Instead of incrementing counter that way, do this:
counter = (counter + 1) % pictures.Length;
You’re now, that counter will in-bounds - If counter goes the length, it goes back to
zero (Just work out the math for it some simple numerical examples you’re scratching your head about it)
That will make sure counter will remain in-bounds as well.
I did a pictures.Length-1` cause both the MIN and MAX values in Clamp are inclusive.
No need for if (Film == True) - ‘if’ takes a boolean expression, ie something that returns either a true/false - Since boolean variables hold a boolean expression, you could just do if (Film) - Doing if (Film == True) is like doing if (True == True) (Assuming Film was actually true)
Don’t use the Array class - Either use a regular array or a generic list. See.
Check out UVT - Lite for a better implemented pictures sequence player - The lite version is free and you get to see the code - You’ll see that he’s loading the images as need dynamically, as opposed to your script that’s adding all the images at once, the moment you hit play which causes a lot of overhead.