using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moving : MonoBehaviour {
public bool isFacingRight;
public float speed;
public float hp;
void Update () {
if (transform.localScale.x == 1) {
isFacingRight = true;
}else{
isFacingRight = false;
}
if (Input.GetKey("left")) {
if (isFacingRight) {
Flip();
}
transform.position -= new Vector3(speed * Time.deltaTime, 0 , 0);
}
if (Input.GetKey("right")) {
if (!isFacingRight) {
Flip();
}
transform.position += new Vector3(speed * Time.deltaTime, 0 , 0);
}
if (Input.GetKey("up")) {
transform.position += new Vector3(0, speed * Time.deltaTime, 0);
}
if (Input.GetKey("down")) {
transform.position -= new Vector3(0, speed * Time.deltaTime, 0);
}
}
void Flip () {
transform.localScale = new Vector3(-transform.localScale.x, 1, 1);
}
}