Shoot-N-Slash/Assets/Scripts/Player.cs
2026-06-04 04:40:36 -07:00

23 lines
548 B
C#

using System;
using UnityEngine;
public class Player : Entity
{
[Header("Ground Detection")]
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;
private void FixedUpdate()
{
Vector2 movement = new Vector2(Input.GetAxis("Horizontal") * speed, rb.linearVelocityY);
if (Input.GetKeyDown(KeyCode.Space) && OnGround())
{
movement.y = jumpPower;
}
rb.linearVelocity = movement;
}
private bool OnGround()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.05f, groundLayer);
}
}