PlayQueued具有不同的动画状态

时间:2012-01-31 21:12:27

标签: animation unity3d

制作任何动画并尝试在其上使用我的代码。我想要实现的是使用PlayQueued多次播放动画,每次都有不同的动画状态,例如反转动画。

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    Animation a;

    void Start () {
        a = animation;
        Invoke("PlayAnimation3",0.3f);
    }

    void PlayAnimation0(){
        //no problem at all...
        a.PlayQueued("simpleAnimation");
        a.PlayQueued("simpleAnimation");
        a.PlayQueued("simpleAnimation");
    }

    void PlayAnimation1(){
        //but when you change AnimationState...
        a.PlayQueued("simpleAnimation");
        AnimationState as0 = a.PlayQueued("simpleAnimation");
        as0.time = as0.length;
        as0.speed = -1f;
        AnimationState as1 = a.PlayQueued("simpleAnimation");
        //... the last AnimationState is the one that counts
        as1.time = 0f;
        as1.speed = 1f;
    }

    void PlayAnimation2(){
        //making a copy of animation does not help
        a.PlayQueued("simpleAnimation");
        AnimationState as0 = a.PlayQueued("simpleAnimation");
        as0.time = as0.length;
        as0.speed = -1f;
        AnimationState as1 = a.PlayQueued("simpleAnimationCopy");
        as1.time = 0f;
        as1.speed = 1f;
    }

    void PlayAnimation3(){
        //it seems duplicated animations have common AnimationState...
        a["simpleAnimationCopy"].time =a["simpleAnimationCopy"].length;
        a["simpleAnimationCopy"].speed =-1f;
        a.Play("simpleAnimation");
        a.PlayQueued("simpleAnimationCopy");
        a.PlayQueued("simpleAnimation");
    }

    void PlayAnimation4(){
        //any ideas? how to use PlayQueued with different animation states?
    }

}

0 个答案:

没有答案
相关问题