Unity动画中加入触发事件
发表于2018-05-31
在模型的动作中,插入个事件回调,常用于碰撞框开启和关闭、播放特效等。下面分别给大家介绍下在Animator动画状态机模式和Animation模式下加入触发事件。




1、Animator模式
首先在模型上挂个脚本

代码如下:
public class charEvents : MonoBehaviour { public void ActionEvent1(string _arg1) { Debug.LogFormat("--- arg3:{0}", _arg1); } }
双击状态,在 Events 中添加事件,输入方法名 ActionEvent1,随便个参数

注意事项:
- 只能在 ActionEvent1 声明0或1个参数,否则会报错
- Failed to call AnimationEvent ActionEvent1 of class charEvents.
- The function must have either 0 or 1 parameters and the parameter can only be: string, float, int, enum, Object and AnimationEvent.
2、Animation模式
在该模式下,会发现在模型的动画都是 read-only,不能编辑及插入事件,而自定义的animation就可以

解决方法:
直接把对应的动画重新拖进对应的动画中,就可以编辑加事件回调了。

来自:https://blog.csdn.net/yangxuan0261/article/details/52335575
如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引