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

来源:互联网 发布:centos安装pdo 编辑:程序博客网 时间:2024/06/07 01:59
    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("不存在该动画");
        }
    }
0 0
原创粉丝点击