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

public class Player : MonoBehaviour
{

    private Vector2 targetPos;
    public float Increment = 5f;

    public float speed;
    public float maxHeight;
    private bool canJump = false;
    public float jumpingForce = 10f;

    private void Update()
    {

        //transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);

        if(Input.GetKeyDown(KeyCode.UpArrow) && transform.position.y < maxHeight && canJump){

            targetPos = new Vector2(transform.position.x, transform.position.y + Increment);
            transform.position = targetPos;
            Debug.Log("Up Arrow was pressed");
            canJump = false;
			GetComponent<Rigidbody>().AddForce(0,jumpingForce,0);
		}

        void OnCollisionEnter(Collision collision){
            Debug.Log("Collision");
		    if (collision.transform.name == "Floor"){
			canJump = true;
		}
	}

    }
}
