gpt4 book ai didi

Unity. Animation not playing when I press button (SetTrigger)(团结一致。按下按钮时不播放动画(SetTrigger))

转载 作者:bug小助手 更新时间:2023-10-24 21:47:36 25 4
gpt4 key购买 nike



I'm trying to make this 2D character play an attack animation when I do left click, I know I cannot do that with just Animator.Play because its only playing for the frame which Input.GetMouseButton(0) is true, right?

我试图让这个2D角色在我点击鼠标左键的时候播放一个攻击动画,我知道我不能只用Animator来做到这一点。播放是因为它只播放Input.GetMouseButton(0)为真的帧,对吗?


So I checked online and I saw that I had to use a trigger parameter instead, because its true then after the animation is done, its not true, so it would work.

所以我在网上查看,我发现我必须使用触发器参数,因为它是真的,然后在动画完成后,它不是真的,所以它可以工作。


This is the code:

代码是这样的:


if (Input.GetMouseButton(0))
{
anims.SetTrigger("Attacking");
}

And this is the animator:
enter image description here

这是动画师:在这里输入图像描述


As you can see all seems to be set correctly and then here you can see compiling the game, it even triggers true when I click the mouse, but the transition from idle to attack doesn't happen:
enter image description here

正如你所看到的,一切似乎都被正确设置了,然后你可以在这里看到编译游戏,当我点击鼠标时,它甚至会触发True,但从空闲到攻击的转换并没有发生:在这里输入图像描述


What could be wrong here?

这里可能出了什么问题?


Thank you for your time and help!

感谢您的时间和帮助!


I checked online and I saw that I had to use a trigger parameter instead, because its true then after the animation is done, its not true, so it would work.

我在网上查看,我发现我必须使用触发器参数,因为它是真的,然后在动画完成后,它不是真的,所以它可以工作。


更多回答

what does your transition from attack back to idle look like? Maybe it is triggered immediately as well?

你从进攻回到空闲状态的转变是什么样子的?也许它也是立即被触发的?

Hi! At the end I solved the problem, I don't know exactly why it happened but I was calling the other animations with the method anims.Play() while a condition was met, so it wasn't triggered only once, whatever, at the end I just made them all work through triggers instead, and it worked.

嗨!最后我解决了这个问题,我不知道它到底为什么会发生,但我使用了Anims.Play()方法调用其他动画,当满足一个条件时,所以它不是只触发一次,无论如何,最后我只是让它们都通过触发器工作,它起作用了。

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com