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 "); } }
OnStateMachineEnter | Called 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. |
OnStateMachineExit | Called 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. |
OnStateEnter | Called on the first Update frame when a state machine evaluate this state. |
OnStateExit | Called on the last update frame when a state machine evaluate this state. |
OnStateIK | Called right after MonoBehaviour.OnAnimatorIK. |
OnStateMove | Called right after MonoBehaviour.OnAnimatorMove. |
OnStateUpdate | Called at each Update frame except for the first and last frame. |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | El nombre del objeto. |
GetInstanceID | Devuelve el id de la instancia del objeto. |
ToString | Returns the name of the object. |
Destroy | Removes a GameObject, component or asset. |
DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindObjectOfType | Devuelve el primer objeto activo cargado de tipo type. |
FindObjectsOfType | Devuelve una lista de todos los objetos activos cargados de tipo type. |
Instantiate | Clona el objeto original y devuelve el clon. |
CreateInstance | Crea una instancia de un objeto scriptable. |
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. |
Awake | Esta función se llama cuando el script ScriptableObject empieza. |
OnDestroy | Esta función se llama cuando el objeto scriptable se destruirá. |
OnDisable | Esta función se llama cuando el objeto scriptable se va fuera del alcance (scope). |
OnEnable | Esta función se llama cuando el objeto es cargado. |