using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts
{
public class PlayerController : MonoBehaviour
{
private float moveInput;
private Rigidbody2D rigidbody;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGrounded;
[SerializeField] private float speed;
[SerializeField] private float jumpForce;
private void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rigidbody.velocity = new Vector2(moveInput * speed, rigidbody.velocity.y);
if(facingRight == false && moveInput > 0)
{
Flip();
}
else if(facingRight == true && moveInput < 0)
{
Flip();
}
}
void update()
{
isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGrounded);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
{
rigidbody.velocity = Vector2.up * jumpForce;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
}