using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
Rigidbody2D rb;
public float speed;
public float jumpHeight = 13.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Flip();
}
void FixedUpdate()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal")* speed, rb.velocity.y);
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(transform.up * jumpHeight, ForceMode2D.Impulse);
}
}
void Flip()
{
if (Input.GetAxis("Horizontal") > 0)
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
if (Input.GetAxis("Horizontal") < 0)
{
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
}
}