您的位置:首页 > 移动开发 > Unity3D

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

2016-06-07 17:09 525 查看
    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> ().wrapMode= WrapMode.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> ().wrapMode= WrapMode.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> ().wrapMode= WrapMode.Loop;
            }else{
                player.transform.GetComponent<Animation> ().wrapMode= WrapMode.Once;
            }
        } else {
            Debug.Log("不存在该动画");
        }
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: