Unity中Animation动画的相关播放(顺播倒播等)

时间:2022-09-04 04:39:48
    public static void PlayerAnimationPlay(GameObject player,string Name){
        if (player.transform.GetComponent<Animation> () != null) {
            player.transform.GetComponent<Animation> ().Play(Name);
        } else {
            Debug.Log("不存在该动画");
        }
    }

    public static void AnimationPlay(GameObject player,string Name){
        if (player.transform.GetComponent<Animation> () != null) {
            Animation curAnimation = player.transform.GetComponent<Animation>();
            player.transform.GetComponent<Animation> ().wrapModeWrapMode.Once;
            curAnimation[Name].time =curAnimation[Name].clip.length - curAnimation[Name].clip.length;
            curAnimation[Name].speed = 1;
            curAnimation.Play(Name);
        } else {
            Debug.Log("不存在该动画");
        }
    }

    public static void AnimationBackPlay(GameObject player,string Name){
        if (player.transform.GetComponent<Animation> () != null) {
            Animation curAnimation = player.transform.GetComponent<Animation>();
            player.transform.GetComponent<Animation> ().wrapModeWrapMode.Once;
            curAnimation[Name].time =curAnimation[Name].clip.length;
            curAnimation[Name].speed = -1;
            curAnimation.Play(Name);   
        } else {
            Debug.Log("不存在该动画");
        }
    }

    public static void PlayerAnimationPlayAndSetState(GameObject player,string Name,bool loop){
        if (player.transform.GetComponent<Animation> () != null) {
            player.transform.GetComponent<Animation> ().Play(Name);
            if(loop){
                player.transform.GetComponent<Animation> ().wrapModeWrapMode.Loop;
            }else{
                player.transform.GetComponent<Animation> ().wrapModeWrapMode.Once;
            }
        } else {
            Debug.Log("不存在该动画");
        }
    }