using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class control : MonoBehaviour {
public float speed = 20f;
public float horizontalSpeed;
float speedX;
public float verticalImpulse;
Rigidbody2D rb;
private bool faceRight = true;
void Start () {
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate () {
float moveX = Input.GetAxis ("Horizontal");
if (Input.GetKey(KeyCode.A))
{
speedX = -horizontalSpeed;
}
else if (Input.GetKey(KeyCode.D))
{
speedX = horizontalSpeed;
}
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(new Vector2(0, verticalImpulse),ForceMode2D.Impulse);
}
transform.Translate(speedX, 0, 0);
speedX = 0;
if (moveX > 0 && !faceRight)
{
flip();
}
else if (moveX < 0 && faceRight)
{
flip();
}
}
void flip()
{
faceRight = !faceRight;
transform.localScale = new Vector3 (transform.localScale.x *-1, transform.localScale.y, transform.localScale.z);
}
}