当前位置:网站首页>Unity code registers events for animation
Unity code registers events for animation
2022-06-10 23:07:00 【Wuzimu】
We can add events to the animation , To automatically play the next animation , The code is as follows
private Animator animator;
private AnimationClip[] clips; // All the animations
private void Awake()
{
animator = GetComponent<Animator>();
clips = animator.runtimeAnimatorController.animationClips;
AddAnimationEvent(clips, "EndEvent",1);
}
/// <summary>
/// Batch register events for animation clips clips Array of animation clips eventName Self defined event instance method name timeRate When the animation is broadcast
/// </summary>
private void AddAnimationEvent(AnimationClip [] clips,string eventName,float timeRate)
{
for (int i = 0; i < clips.Length; i++)
{
AnimationEvent _event = new AnimationEvent();
_event.functionName = eventName;// Set the bound event name
_event.time = clips[i].length * timeRate;// Set the trigger time of the event timeRate =1 That is, when the animation playback is completed
clips[i].AddEvent(_event);
}
}
/// <summary>
/// The instance method of the event
/// </summary>
private void EndEvent()
{
print(" The animation is finished ");
// End animation , According to the choice , Auto play or no auto play
GameController.Instance.AutoPlay();
}
边栏推荐
- Swin_ Interpretation of transformer source code
- kubernetes多网卡方案之Multus CNI部署和基本使用
- smb匿名
- Opencv_100问_第四章 (16-20)
- Icml2022 | reexamine end-to-end voice to text translation from scratch
- Online questionnaire system based on php+web+mysql
- 线程池——治理线程的法宝
- ICML2022 | 从零开始重新审视端到端的语音到文本翻译
- Interpreting the registry class of mmcv
- Opencv_ 100 questions_ Chapter II (6-10)
猜你喜欢

"Draw the bow as strong, use the arrow as long", Manfu technology opens a new track for the data service industry

Digital twin: third person mouse operation

ICML2022 | 从零开始重新审视端到端的语音到文本翻译

Html+php+mysql login registration page

JS sensitive information leak detection tool
A journey of database full SQL analysis and audit system performance optimization

Redis from entry to entry

原生支持 ARM64 的首个版本!微软 Win11/10 免费工具集 PowerToys 0.59 发布

数据与信息资源共享平台(九)

Fallback operation in SVN
随机推荐
2022 t elevator repair test question simulation test question bank and online simulation test
Flex layout syntax
Informatics Olympiad all in one 1280: [example 9.24] skiing | openjudge noi 2.690: skiing | Luogu p1434 [show2002] skiing
[raise bar C #] how to call the base of the interface
Bottom layer communication protocol ① of single chip microcomputer -- synchronous and asynchronous, parallel and serial, full duplex and half duplex, simplex, level signal and differential signal
Static routing configuration of serial interface in router experiment (Supplement)
200 c language words, please collect!
UE4 getting started with bone animation
Reflow and repaint
Thread pool: a magic weapon for managing threads
CCF CSP 202109-4 collect cards
Redis数据结构
DC2 of vulnhub
Pki/tls Swiss Army knife cfssl
SMB anonyme
Software project management 6.10 Cost budget
C language internal skill cultivation [integer stored in memory]
玩电子,穷三代
【006】初识字符串
同花顺开户怎么样?开户安全吗?