Unity 技巧之 动画相关操作

一、Unity 模型使用“Animation”播放动画

1、指定动画:Animation

2、取消自动播放:Play Automatically

3、Ctrl+6打开Animation可视化界面

二、Unity 模型Animator 改为 Animation

将“Animator”改为“Animation”:在“Project”里选中模型——在“Inspector”点击“Rig”——“Animation Type”选择“Legacy”——点击“Apply”即可

三、Untiy Start 里播放动画

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationOperate : MonoBehaviour
{
    private Animation _Animation;

    // Start is called before the first frame update
    void Start()
    {
        // 动画
        _Animation = gameObject.GetComponent<Animation>();

        // 播放默认动画
        _Animation.clip = _Animation.GetClip(Movement.ToString());
        _Animation.playAutomatically = true;
    }

    // Update is called once per frame
    void Update()
    {
    
    }
}

四、Unity 动画倒播

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationOperate : MonoBehaviour
{
    // 动画状态机
    private Animation _Animation;

    // 动画状态
    private AnimationState _AnimationState;

    // 动画名称
    private string _AnimationName = "Take 001";

    // Start is called before the first frame update
    void Start()
    {
        // 动画状态机
         _Animation = gameObject.GetComponent<Animation>();

        // 动画播放模式
        _Animation.wrapMode = WrapMode.Once;

        // 动画状态
        _AnimationState = _Animation[_AnimationName];

        // 这里把动画的当前帧变为该动画的最后一帧
        _AnimationState.time = _Animation.clip.length;

        // 速度调为-1
        _AnimationState.speed = -1f;

        // 播放
        _Animation.Play();
    }

    // Update is called once per frame
    void Update()
    {
        // 判断动画播放完成
        if (_Animation.IsPlaying(_AnimationName))
        {
            // 释放脚本
            Destroy(this);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值