using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpacebarToJump : MonoBehaviour
{
    public float jumpForce = 1.0f;
    Rigidbody thisRB;

    // Start is called before the first frame update
    void Start()
    {
        // get a reference to the rigidbody object (on the current game object) so we can manipulate it through code
        thisRB = gameObject.GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        // GetKeyDown will only trigger once per spacebar press, as opposed to GetKey, which fires off constantly
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // use the rigidbody we grabbed earlier (thisRB) and add force to it in the Y direction (which is normally up)
            thisRB.AddForce(new Vector3(0f, jumpForce, 0f));
        }
    }
}