- Home /
Jump by touch
Hello all, I am working on game that jump when you touch the screen and I want you jump while you touch the screen with one finger with a limit time for jumping (.2 s), I made a code but I don't know why it doesn't work & here it is: bool jumpingPossible; float jumpingTimer; void FixedUpdate (){ if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ { jumpingPossible = true; jumpingTimer = 0f; } if(jumpingPossible) { rigidbody.AddForce(0f, 30f, 0f); jumpingPossible = jumpingTimer <= 0.2f; jumpingTimer += Time.deltaTime; if( Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled) jumpingPossible = false; } }
and I'll be relly grateful for who help
Answer by jacobkaniuk · Mar 31, 2014 at 06:01 PM
Try to set your variables at the top (jumpingpossible and jumpingtimer) equal to false and zero, then within the function they are being called in they will change and use the new values inside the function.