Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Refactoring of Jumping

private void Jump() {
    if (touchingPlatform) {
        rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
        touchingPlatform = false; // This allow one jump after colliding with side of platform, but not more
    }
    else if (boosts > 0) {
        rigidbody.AddForce(boostVelocity, ForceMode.VelocityChange);
        boosts -= 1;
        GUIManager.SetBoosts (boosts);
    }
}

Read Tap as Jump

if ((Input.GetButtonDown("Jump")) ||
    ((Application.platform == RuntimePlatform.Android) && (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))) {
    // your code here
}