using UnityEngine;
public class Move : MonoBehaviour
{
public float speed = 200f;
private Rigidbody2D rb;
private bool fall;
private bool faceRight = true;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
rb.MovePosition(rb.position + Vector2.right * moveX * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
rb.AddForce(Vector2.up * 50000);
if (moveX > 0 && !faceRight)
flip();
else if (moveX < 0 && faceRight)
flip();
}
void flip(){
faceRight = !faceRight;
transform.lossyScale = new Vector3(transform.lossyScale.x * -1, transform.lossyScale.y, transform.lossyScale.z);
}
}