简体   繁体   English

按下按钮时无法播放 animation

[英]cant play an animation when pressing a button

screen shot of the animator panel动画师面板的屏幕截图

so as you can see I am trying to play an animation called Attack when triggering the parameter Attack but whenever I press the triggering button that I chose the animation just doesn't work and the trigger does not get activated如您所见,我在触发参数 Attack 时尝试播放名为 Attack 的 animation 但是每当我按下选择 animation 的触发按钮时,它就不起作用并且触发器没有被激活

here is my code这是我的代码

using System.Collections; using System.Collections.Generic; using UnityEngine; public class attack: MonoBehaviour { public Animator animator; void Update() { if (Input.GetKeyDown(KeyCode.C)) { Attack(); } } void Attack() { animator.SetTrigger("Attack"); } }

by the way, I am trying to follow this guy's video顺便说一句,我正在尝试关注这个人的视频

https://youtu.be/sPiVz1k-fEs https://youtu.be/sPiVz1k-fEs

Suggestions:建议:

  1. Make sure you have assigned this script to a game object.确保您已将此脚本分配给游戏 object。
  1. Assign the right animator that you want to animate in inspector of this script.在此脚本的检查器中分配要设置动画的正确动画师。
  1. Check if you have added 'Attack' parameter in that animator and the spelling is same like the one mentioned as parameter in your code.检查您是否在该动画师中添加了“攻击”参数,并且拼写与代码中提到的参数相同。
  1. and lastly check if you have set the trigger for the transition of animation in the animator( in animator its the arrow that is pointing towards your animation ).最后检查您是否在动画器中设置了 animation 过渡的触发器(在动画器中,它的箭头指向您的 animation )。

Let me know if you don't understand any of this I'll breifly explain.让我知道,如果你不明白这些,我会简要解释。

Hopefully that will help... Happy coding:)希望这会有所帮助......快乐的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM