Created
July 17, 2015 06:09
-
-
Save kuriharaan/2c4c620d74869e384899 to your computer and use it in GitHub Desktop.
Sample for StateMachineBehaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class ForbidWalk : StateMachineBehaviour { | |
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state | |
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { | |
animator.SetBool("CanWalk", false); | |
} | |
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks | |
//override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { | |
// | |
//} | |
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state | |
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { | |
animator.SetBool("CanWalk", true); | |
} | |
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here | |
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { | |
// | |
//} | |
// OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here. | |
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { | |
// | |
//} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
[RequireComponent(typeof(Animator))] | |
public class Player : MonoBehaviour { | |
void Update () { | |
var animator = GetComponent<Animator>(); | |
if(animator.GetBool("CanWalk")) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment