- Home /
How can I move back to Element 0 in an array to reset a loop?
Hi, I have an array that loops but will change to another array once a condition is met. After that array is over, I want it return to the first. I need it to return at Element 0, however. Instead, it just picks up where it left off in the original sequence. Any ideas?
private var csScript : Main;
var textures : Texture[];
var changeInterval : float = 0.33;
var textures2 : Texture[];
var changeMe : boolean = false;
function Awake()
{
//Get the CSharp Script
csScript = this.GetComponent("Main");//Don't forget to place the 'CSharp1' file inside the 'Standard Assets' folder
}
function Update() {
if( textures.length == 0 ) // nothing if no textures
return;
// we want this texture index now
var index : int = Time.time / changeInterval;
var index2 : int = Time.time / changeInterval;
// take a modulo with size so that animation repeats
if(csScript.janneleIsWaiting){
index = index % textures.length;
// assign it
renderer.material.mainTexture = textures[index];
}
if(csScript.janelleWorried){
print("so so worried");
index2 = index2 % textures2.length;
// assign it
renderer.material.mainTexture = textures2[index2];
reset();
}
}
function reset(){
yield WaitForSeconds(.35);
csScript.janneleIsWaiting = true;
csScript.janelleWorried = false;
csScript.janelleHappy = false;
}
Comment
Answer by siaran · Mar 15, 2015 at 08:36 PM
set the index you use to access the first array to 0 when you go back to it?