unity中animator的使用

unity中animator的使用

  1. 添加Animator Controller,并设置状态机
    在这里插入图片描述
    在这里插入图片描述

  2. 给GameObject添加Animator组件,并把刚才创建的Animator Controller赋值给它
    在这里插入图片描述

  3. 在脚本中进行声明,获取,并且在合适的时机,进行合适的参数设置

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

public class PlayerHp : MonoBehaviour
{
	//声明Animator
    private Animator _mAnimator;

    // Start is called before the first frame update
    void Start()
    {
    	//获取组件
        _mAnimator = GetComponent<Animator>();
    }

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

    }

    public void TakeDamage()
    {
    		//给我们在Animator Controller面板中设置的参数赋值
            _mAnimator.SetBool("isDeath", true);
    }
}

发布了201 篇原创文章 · 获赞 210 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40666620/article/details/104693365