using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayercontrollerScript : MonoBehaviour
{
private float movementInputDirection;
private bool isFacingRight = true;
private bool IsWalking;
private Rigidbody2D rb;
private Animator anim;
public float movementSpeed = 2f;
public float JumpForce = 5.0f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
anim = GetComponent();
}
// Update is called once per frame
void Update()
{
CheckInput();
CheckMovementDirection();
UpdateAnimations();
}
private void FixedUpdate()
{
ApplyMovement();
}
if(rb.velocity.x != 0))
{
IsWalking = true;
}
{
IsWalking = false;
}
private void UpdateAnimations();
private void CheckMovementDirection()
{
if(isFacingRight && movementInputDirection < 0)
{
Flip();
}
else if(!isFacingRight && movementInputDirection > 0)
{
Flip();
}
}
private void CheckInput()
{
movementInputDirection = Input.GetAxisRaw(“Horizontal”);
if (Input.GetButtonDown(“Jump”))
{
Jump();
}
}
private void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, JumpForce);
}
private void ApplyMovement()
{
rb.velocity = new Vector2(movementSpeed * movementInputDirection,rb.velocity.y);
}
private void Flip()
{
isFacingRight = !isFacingRight;
transform.Rotate(0.0f, 180.0f, 0.0f);
}
}