📜  动画结束时的统一调用函数 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:02.095000             🧑  作者: Mango

代码示例1
// 1. click on the animation state block in the animator and in the inspector
// 2. click Add Behavior button and edit that new script
// 3. find the OnStateExit function and un-comment it. Example below.

// 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)
{
  GameObject self = animator.gameObject; //a reference to the gameobject being animated
  MyScript script = self.GetComponent();
  Debug.Log("Animation has finished!");
  script.SendMessage("MyFunction"); //this is the name of the function to call
}