Character.cs

This commit is contained in:
AlexKochnev 2022-04-03 02:51:35 +03:00
parent d9c039760e
commit 5ab9194359

View File

@ -7,6 +7,7 @@ public class Character : MonoBehaviour
[SerializeField] private float health; [SerializeField] private float health;
[SerializeField] private float damage; [SerializeField] private float damage;
[SerializeField] private float moveSpeed; [SerializeField] private float moveSpeed;
[SerializeField] private GameObject characterSprite;
private float horInpt; private float horInpt;
private float verInpt; private float verInpt;
@ -30,6 +31,14 @@ void Update()
if (-0.1f > horInpt || horInpt > 0.1f) if (-0.1f > horInpt || horInpt > 0.1f)
{ {
transform.position += new Vector3(horInpt * moveSpeed,0,0); transform.position += new Vector3(horInpt * moveSpeed,0,0);
if(horInpt > 0 && characterSprite.transform.localScale.x > 0)
{
characterSprite.transform.localScale = new Vector3(-1, 0, 0);
}
if (horInpt < 0 && characterSprite.transform.localScale.x < 0)
{
characterSprite.transform.localScale = new Vector3(1, 0, 0);
}
} }
if (-0.1f > verInpt || verInpt > 0.1f) if (-0.1f > verInpt || verInpt > 0.1f)
{ {