1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

using AnimatorAccess ; public class Player : MonoBehaviour { ExamplePlayerAnimatorAccess anim ; Animator animator ; int currentState0 ; public float speed ; public float maxSpeed = 5f ; float horizontalInput ; bool jumpKeyPressed = false ; void Awake ( ) { animator = GetComponent < Animator > ( ) ; anim = GetComponent < ExamplePlayerAnimatorAccess > ( ) ; } void OnEnable ( ) { anim . State ( anim . stateIdIdle ) . OnActive += OnIdle ; anim . State ( anim . stateIdJumping ) . OnEnter += OnEnterJumping ; anim . TransitionTo ( anim . stateIdWalking ) . OnStarted += OnStartedTransitionToWalking ; } void OnDisable ( ) { anim . OnStateChange -= OnStateChange ; } void OnStartedTransitionToWalking ( TransitionInfo info , LayerStatus status ) { Debug . Log ( "Called when any transiton with target walking is starting" ) ; } void OnIdle ( StateInfo info , LayerStatus status ) { Debug . Log ( "OnIdle: called every frame while in state idle" ) ; } void OnEnterJumping ( StateInfo info , LayerStatus status ) { Debug . Log ( "OnEnterJumping: Jump, called once " ) ; } void Update ( ) { horizontalInput = Input . GetAxis ( "Horizontal" ) ; jumpKeyPressed = Input . GetKeyDown ( KeyCode . UpArrow ) ; } void FixedUpdate ( ) { if ( anim . IsJumping ( ) ) { // alternatively use polling to check for state changes instead of events } if ( jumpKeyPressed ) { anim . SetJumpTrigger ( ) ; } speed = horizontalInput * maxSpeed ; anim . SetSpeed ( Mathf . Abs ( speed ) ) ; // alternative (not recommended) way of accessing hash IDs directly: // animator.SetFloat (anim.paramIdSpeed, Mathf.Abs (speed)); } }