Question by
TheSorcerer · Jan 04, 2017 at 01:09 PM ·
scripting problemanimatortouch controlsswipe2d platformer
After swiping down, I want player to slide once, instead of infinitely looping his animation, script attached below
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
fingerStart = touch.position;
fingerEnd = touch.position;
}
if (touch.phase == TouchPhase.Moved)
{
fingerEnd = touch.position;
if (Mathf.Abs(fingerEnd.y - fingerStart.y) > 150)
{
if (fingerEnd.y - fingerStart.y > 150)//up swipe
{
if (grounded)
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
}
if (fingerEnd.y - fingerStart.y < -150 && !sliding)
{
sliding = true;
myAnimator.SetBool("Slide", true);
}
if (!(fingerEnd.y - fingerStart.y < -150) && sliding)
{
sliding = false;
myAnimator.SetBool("Slide", false);
}
When I swipe down to slide, my player slides infinitely, there is no problem with jump, when he is infinitely sliding when I swipe up to jump, he jumps and starts to break the slide loop, my parameters from RUN->SLIDE are Slide = true and SLIDE->RUN are Slide = false. How to change the script so as to change the boolean to false when he finishes sliding once, I am a complete beginner, I got this far from tutorials and combining different scripts, I have no idea what I should do to
Comment