Version: 2019.4
State Machine Basics
State Machine Transitions

Параметры анимации

Animation Parameters are variables that are defined within an Animator Controller that can be accessed and assigned values from scripts. This is how a script can control or affect the flow of the state machine.

Параметры анимации - это переменные, которые определены в анимационной системе, но также могут быть доступны и изменены из скриптов. Например, значение параметра может быть изменено с помощью анимационной кривой, а затем получено из скрипта, чтобы, например, изменить высоту звукового эффекта, как если бы он был частью анимации. Аналогично, скрипт может устанавливать значения параметров для подхвата системой Mecanim. Например, скрипт может выставить параметр для контроля дерева смешивания.

Default parameter values can be set up using the Parameters section of the Animator window, selectable in the top right corner of the Animator window. They can be of four basic types:

  • Integer - a whole number
  • Float - число с плавающей запятой
  • Bool - логическое значение правда / ложь
  • Trigger - логический параметр, который сбрасывается контроллером при потреблении переходом.

Parameters can be assigned values from a script using functions in the Animator class: SetFloat, SetInteger, SetBool, SetTrigger and ResetTrigger.

Ниже приведен пример скрипта, который модифицирует параметры основываясь на вводе пользователя.

using UnityEngine;
using System.Collections;

public class SimplePlayer : MonoBehaviour {
    
    Animator animator;
    
    // Use this for initialization
    void Start () {
        animator = GetComponent<Animator>();
    }
    
    // Update is called once per frame
    void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        bool fire = Input.GetButtonDown("Fire1");

        animator.SetFloat("Forward",v);
        animator.SetFloat("Strafe",h);
        animator.SetBool("Fire", fire);
    }

    void OnCollisionEnter(Collision col) {
        if (col.gameObject.CompareTag("Enemy"))
        {
            animator.SetTrigger("Die");
        }
    }
}


State Machine Basics
State Machine Transitions
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961