How to force a button to release through code?

Updated on August 20, 2019 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on August 19, 2019

Right now what I have set up is an event trigger on a UI Button that when the user presses and holds down the button it will hold the character in place and when the user lets go of the button the character is able to move again. What I am trying to do is have it so after a certain amount of time has passed of the user holding down the button the character will just start moving. No matter how long the user holds down the button the character will start moving after a certain amount of time has passed. Here is the code that I have right now. All that happens right now is when the user holds down the button the character stops moving but if the user keeps holding down the button the character will not move. I am unable to get it so that the character will start moving after a certain amount of time.

 

   if (_sliding && timer >= 0.2)
   {
   rb.constraints = RigidbodyConstraints.FreezePositionY;
   }
   else if (!_sliding || timer >= 0.4)
   {
   rb.constraints &= ~RigidbodyConstraints.FreezePositionY;
   rb.constraints = RigidbodyConstraints.FreezePositionX;
   }

 

The timer I have running in a different part of the code. The timer only runs when the user presses and holds down the button.

If anybody has any suggestions that would be great!

Thanks

  • Liked by
Reply
0 on August 20, 2019

Can you show the code where the player should start moving again?

  • Liked by
Reply
Cancel