Unity动画系统(2)

发布于:2024-07-03 ⋅ 阅读:(113) ⋅ 点赞:(0)

6.1 动画系统基础2-3_哔哩哔哩_bilibili

p316

模型添加Animator组件

动画控制器

AnimatorController

AnimatorController

可以通过代码控制动画速度

建立动画间的联系

bool值的设定

trigger

p318

trigger点击的时候触发,如喊叫,开枪及换子弹等,执行完成后自动回复原状态

通过代码调整动画播放速度

动画播放速度与某一个参数关联到一起

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

public class EthanController : MonoBehaviour
{
    private Animator ani;
    private void Awake()
    {
        ani = GetComponent<Animator>();
    }

    private void Update()
    {
        动画参数名称可以转换为一个ID【int】
        //int id = Animator.StringToHash("CanMove");
        //Debug.Log("ID"+id);
        设置后读取动画参数
        //ani.SetBool("CanMove",true);
        [使用HashID进行参数的设置或读取,效率更高]
        //ani.SetBool(id, true);

        //ani.SetFloat
        //ani.GetFloat
        //ani.SetInteger
        //ani.GetInteger
        //ani.SetTrigger
        //ani.SetTrigger [触发参数]

        ani.SetFloat("ShoutPlaySpeed", 2);
        ani.SetFloat("ShoutPlaySpeed",2,0.5f,Time.deltaTime);

        //按下方向键左键
        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
            ani.SetBool("CanMove", true);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow)) {
            ani.SetBool("CanMove", false);
        }

        if (Input.GetKeyDown(KeyCode.Space)) {
            ani.SetTrigger("Shout");
        }
        if (Input.GetKey(KeyCode.S)) {
            //设置喊叫动画的播放速度,有0.5s过渡时间
            ani.SetFloat("ShoutPlaySpeed",2,0.5f,Time.deltaTime);
        }
    }
}
 


网站公告

今日签到

点亮在社区的每一天
去签到