如果玩家希望他们可以持有动画但如果他们不持有它,我该如何做到这一点,它会完成..(基于物理)

How do I make it so if the player wants they can hold the animation but if they don't hold it, it completes.. (physics based)

场景是这样的, 我希望玩家能够执行一个技巧,然后如果他们愿意,可以将技巧保持更长的时间,但是如果他们不保持输入,那么他们就会像我一样继续动画直到完成我实际上并没有尝试实施太多,但没有给我想要的结果,我想我只是问问人们是否已经这样做了,这样我就不会在接下来的 2 个小时里陷入困境,感谢所有帮助,谢谢! :D

(统一脚本)

{

 [Header("Trick Attributes")]
 public string GroundTagName;        // Tag used for all the platforms
 public KeyCode stuntKey;
 public float AnimationFreezeTime = 0.75f;
 public SpriteAnimator anim;     // Put the Sprite animator here
 public Animator spriteAnimator;  // Put the Animator here
 private bool isGrounded;
 public bool stunting = false;

 private void Start()
 {
     
 }

 private void Update()
 {
     if (Input.GetKeyDown(stuntKey) && !isGrounded)
     {
         anim.StartAnimation("FlyingSquirrel");
         stunting = true;
         Invoke("FreezeAnimation", AnimationFreezeTime);
     }
     if (Input.GetKeyUp(stuntKey))
     {
         stunting = false;
         spriteAnimator.speed = 1;
     }
 }

 void FreezeAnimation() {
     spriteAnimator.speed = 0;

 }

 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == GroundTagName)
     {
         isGrounded = true;

     }
     else
     {
         isGrounded = false;
     }

     if (stunting && collision.gameObject.tag == GroundTagName)
     {
         Destroy(gameObject);
     }
 }

 private void OnCollisionExit(Collision collision)
 {
         isGrounded = false;
 }

}

FlyingSquirrel 需要分成 3 个不同的动画。这可以在 Maya、Blender、uMotion 甚至 Unity 的动画导入器中完成:

您需要 3 个 Animator 状态:

  • Start_FlyingSquirrel // 玩家移动到位置
  • Idle_FlyingSquirrel // 玩家“掌握”了把戏
  • End_FlyingSquirrel // 玩家松手,return 正常

当玩家按下按钮开始技巧时,播放开始动画。对于转换,使用“有退出时间”进入空闲状态。 Idle 状态将为 true(使用布尔 Animator 参数),同时技巧被“保持”。取消选中“有退出时间”以过渡到结束状态 - 您希望这立即发生。