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物体上面绑定的所有脚本的函数)

 

 

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM