using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerJump : MonoBehaviour
{
   
    [SerializeField] private LayerMask GroundLayer;
    [SerializeField] private Transform groundCheck;
    
    private bool isGrounded;
    private float HorizontalInput;

    private Rigidbody2D rb;
    public float JumpPower;
    private Animator anim;
    void Start()
    {
        
        anim = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {


        HorizontalInput = Input.GetAxisRaw("Horizontal");


        if (Input.GetKey(KeyCode.Space))
        {
            Jump();
        }


        anim.SetBool("IsGrounded", isGrounded);

        isGrounded = Physics2D.OverlapBox(groundCheck.position, new Vector2(0.17f, 0.015f), 0, GroundLayer);



    }

    private void Jump()
    {

        if (isGrounded)
        {
            rb.velocity = new Vector3(rb.velocity.x, JumpPower, 0);
            anim.SetTrigger("Jump");
          
        }


    }
 
   
    


}