- Home /
 
 
               Question by 
               Zewlo · Jan 18, 2021 at 11:43 PM · 
                c#animationplayer movementgame development  
              
 
              How do I check if a player is holding a trick and not just tapping it (but i want both)
so here is the scenario, i want the player to be able to perform a trick, and then be able to hold the trick for a longer duration if they want to, but if they don't hold the input then they instead just continue the animation until completion as i haven't actually tried implementing too much and am just looking up if people have already done it so i don't spend the next 2 hours down a rabbit hole, any and all help is appreciated thanks! :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;
     }
 }
 
 
              
               Comment
              
 
               
              Your answer