StateMachineBehaviour

class in UnityEngine

/

Hereda de:ScriptableObject

Cambiar al Manual

Descripción

StateMachineBehaviour is a component that can be added to a state machine state. It's the base class every script on a state derives from.

By default the Animator does instantiate a new instance of each behaviour define in the controller. The class attribute SharedBetweenAnimatorsAttribute control how behaviours are instantiated.

StateMachineBehaviour has some predefined messages: OnStateEnter, OnStateExit, OnStateIK, OnStateMove, OnStateUpdate.

using UnityEngine;

public class AttackBehaviour : StateMachineBehaviour { public GameObject particle; public float radius; public float power;

protected GameObject clone;

override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject; Rigidbody rb = clone.GetComponent<Rigidbody>(); rb.AddExplosionForce(power, animator.rootPosition, radius, 3.0f); }

override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Destroy(clone); }

override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("On Attack Update "); }

override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("On Attack Move "); }

override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("On Attack IK "); } }

Funciones Públicas

OnStateMachineEnterCalled on the first Update frame when making a transition to a state machine. This is not called when making a transition into a state machine sub-state.
OnStateMachineExitCalled on the last Update frame when making a transition out of a StateMachine. This is not called when making a transition into a StateMachine sub-state.

Mensajes

OnStateEnterCalled on the first Update frame when a state machine evaluate this state.
OnStateExitCalled on the last update frame when a state machine evaluate this state.
OnStateIKCalled right after MonoBehaviour.OnAnimatorIK.
OnStateMoveCalled right after MonoBehaviour.OnAnimatorMove.
OnStateUpdateCalled at each Update frame except for the first and last frame.

Miembros heredados

Variables

hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameEl nombre del objeto.

Funciones Públicas

GetInstanceIDDevuelve el id de la instancia del objeto.
ToStringReturns the name of the object.

Funciones Estáticas

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeDevuelve el primer objeto activo cargado de tipo type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClona el objeto original y devuelve el clon.
CreateInstanceCrea una instancia de un objeto scriptable.

Operadores

bool¿Existe el objeto?
operator !=Compare si dos objetos se refieren a un objeto diferente.
operator ==Compara dos referencias de objeto para ver si se refieren al mismo objeto.

Mensajes

AwakeEsta función se llama cuando el script ScriptableObject empieza.
OnDestroyEsta función se llama cuando el objeto scriptable se destruirá.
OnDisableEsta función se llama cuando el objeto scriptable se va fuera del alcance (scope).
OnEnableEsta función se llama cuando el objeto es cargado.
OnValidateThis function is called when the script is loaded or a value is changed in the Inspector (Called in the editor only).
ResetSe re-inicia a los valores predeterminados.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961