34 lines
997 B
Markdown
34 lines
997 B
Markdown
![]() |
#unity/日常积累
|
|||
|
|
|||
|
``` cs
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class RbotArmController : MonoBehaviour
|
|||
|
{
|
|||
|
// 指定animation 动画控制器,在脚本所在的物体上直接拖拽即可
|
|||
|
public Animator armAnimator;
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
// 创建一个事件
|
|||
|
AnimationEvent evt = new AnimationEvent();
|
|||
|
// 绑定触发事件后要执行的方法名
|
|||
|
evt.functionName = "PrintEvent";
|
|||
|
// 执行方法后要传入的参数
|
|||
|
evt.intParameter = 12345;
|
|||
|
// 设置事件关键帧的位置,当事件过了1.3秒后执行
|
|||
|
evt.time = 1.3f;
|
|||
|
// 设置目标动画剪辑
|
|||
|
AnimationClip clip = armAnimator.runtimeAnimatorController.animationClips[0];
|
|||
|
// 绑定事件
|
|||
|
clip.AddEvent(evt);
|
|||
|
}
|
|||
|
// 触发事件后,要执行的方法
|
|||
|
public void PrintEvent(int i)
|
|||
|
{
|
|||
|
print("PrintEvent: " + i + " called at: " + Time.time);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
```
|