void Start () { instance = this; animationHandler = PlayRun; myAnimation = GetComponent<Animation>(); } public void PlayDead() { myAnimation.Play(Dead.name); if (myAnimation[TurnLeft.name].normalizedTime > 0.95f) { animationHandler = PlayRun; } } public void PlayRun() { myAnimation.Play(Run.name); } public void PlayJumpDown() { myAnimation.Play(JumpDown.name); if (myAnimation[JumpDown.name].normalizedTime > 0.95f) { animationHandler = PlayRun; } } public void PlayJumpLoop() { myAnimation.Play(JumpLoop.name); } public void PlayDoubleJump() { myAnimation.Play(Roll.name); if (myAnimation[Roll.name].normalizedTime > 0.95f) { animationHandler = PlayJumpLoop; } } public void PlayJumpUp() { myAnimation.Play(JumpUp.name); } public void PlayRoll() { myAnimation.Play(Roll.name); PlayController.instance.isRoll = true; if (myAnimation[Roll.name].normalizedTime > 0.95f) { animationHandler = PlayRun; PlayController.instance.isRoll = false; } } public void PlayTurnLeft() { myAnimation.Play(TurnLeft.name); if (myAnimation[TurnLeft.name].normalizedTime > 0.95f) { animationHandler = PlayRun; } }
时间: 2024-02-14 20:20:34 浏览: 119
MyAnimation.zip
这是一个 C# 脚本,在 Unity 引擎中用于控制角色动画的播放。在 Start() 函数中,代码通过 GetComponent<Animation>() 获取到当前物体的 Animation 组件,并将 PlayRun 函数赋值给 animationHandler 变量,表示默认播放的是角色跑步动画。该脚本还定义了 PlayDead、PlayRun、PlayJumpDown、PlayJumpLoop、PlayDoubleJump、PlayJumpUp、PlayRoll、PlayTurnLeft 共 8 个函数,分别对应不同的角色动画。这些函数中,都使用 myAnimation.Play() 方法来播放相应的动画,并且使用 normalizedTime 属性来判断动画的播放进度,从而在适当的时候更改 animationHandler 变量的值,以便切换到下一个需要播放的动画。当然,这里的具体实现可能还涉及到其他的逻辑,需要根据实际情况来判断。
阅读全文