using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class DoubleJump : MonoBehaviour {

    [SerializeField] private float jumpForce = 10;
    // [SerializeField] private float checkDistance = 0.3f;
    // [SerializeField] private int maxNumOfJumps = 1;

    private bool isFalling = false;
    private Rigidbody rigidBody;

	void Awake () {
        rigidBody = GetComponent<Rigidbody>();
	}

	void Update () {
        if(Input.GetButton("Jump") && !isFalling) {
	        Jump();
        }
        isFalling = true;
	}

    void Jump() {
        rigidBody.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
        //rigidBody.velocity = new Vector3(rigidBody.velocity.x, rigidBody.velocity.y + jumpForce, rigidBody.velocity.z);
    }

    //bool OnGround() {
    //    Ray groundRay = new Ray(transform.position, Vector3.down);

    //    return (Physics.Raycast(groundRay, checkDistance));
    //}

    void OnCollisionStay() {
        isFalling = false;
    }
}
