如何移回阵列中的元素0以重置循环?

时间:2015-03-14 22:38:29

标签: arrays animation unity3d unityscript

我有一个循环通过一堆图像来制作动画的数组,但是一旦条件满足就会变成另一个数组动画。在该数组结束后,它确实返回到第一个数组。但是,它会从停止的地方开始,而不是重置。我需要它每次都返回元素0。有什么想法吗?

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;
}

0 个答案:

没有答案