按下两个按钮时,动画不起作用-Unity 2d
我正在建立一个统一的2D项目,并且在为玩家制作动画时遇到了一些困难。
简而言之,玩家将有两个动作,分别是“步行”和“步行和射击”。
但是,当我将动画设置为“散步”时,它不会播放该动画。
问题在于必须按两个按钮播放动画。
我该怎么办来解决这个问题?
if (Input.GetKeyDown(KeyCode.Space) && Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
{
_Anim.SetBool("Player_Walk", false);
_Anim.SetBool("Player_Idle", false);
_Anim.SetBool("Player_Idle_Shooting", false);
_Anim.SetBool("Player_Walk_Shooting", true);
}
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
{
_Anim.SetBool("Player_Walk", true);
_Anim.SetBool("Player_Idle", false);
_Anim.SetBool("Player_Idle_Shooting", false);
_Anim.SetBool("Player_Walk_Shooting", false);
}
I'm building a 2d project in Unity and I'm having some difficulty animating the Player.
In short, the Player will have two actions, which are "Walk" and "Walk and Shoot".
However, when I set the animation to "Walk and Shoot" it doesn't play this animation.
The problem is in having to press two buttons to play the animation.
What can I do to resolve this issue?
if (Input.GetKeyDown(KeyCode.Space) && Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
{
_Anim.SetBool("Player_Walk", false);
_Anim.SetBool("Player_Idle", false);
_Anim.SetBool("Player_Idle_Shooting", false);
_Anim.SetBool("Player_Walk_Shooting", true);
}
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
{
_Anim.SetBool("Player_Walk", true);
_Anim.SetBool("Player_Idle", false);
_Anim.SetBool("Player_Idle_Shooting", false);
_Anim.SetBool("Player_Walk_Shooting", false);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您首先需要括号(因为(因为a&&& b || c不等于a&&&(b || c)),然后在第二个之前“ else”,然后“否则”:
我个性化会颠倒那个并写:
对我来说看起来更简单
I suppose you need brackets in first if (because a && b || c is not equal to a && (b || c)) and then "else" before the second if:
I personaly would invert that and write:
That looks simpler to me