Unity 动画系统 AnimationEvent 动画事件

👈返回目录 


AnimationEvent类

 


添加事件的方法:代码添加

目的:

  当某动画的Clip播放0.5秒后,触发自定义事件PrintEvent();

内容:

  创建事件,并设置好传递的参数;事件与Clip绑定;自定义Event函数;

步骤:

1.创建一个动画事件 

AnimationEvent evt = new AnimationEvent();

evt.functionName = "PrintEvent";

evt.intParameter = 12345;

evt.time = 1.3f;

2.具体的事件函数,自己写的函数

public void PrintEvent(int i)

 {

  print("PrintEvent: " + i ); //自定义

 }

3.具体绑定,一般绑在AnimationClip上

Animator anim;

AnimationClip clip;

anim = GetComponent<Animator>();

clip = anim.runtimeAnimatorController.animationClips[0];

clip.AddEvent(evt);

 


添加事件的方法:界面手动添加

1、点击要添加事件的物体,调出Animation窗口,点击下图中的按钮,添加事件

2、选中事件,在Inspector面板中,选择相应的函数(函数列表范围仅限 Pig物体上面绑定的所有脚本的函数)

 

 

 

 

 

 

 

posted @ 2018-11-19 22:48  激情1995  阅读(16713)  评论(0编辑  收藏  举报