Made player turn when directions are pushed.
This commit is contained in:
parent
d0a546ffac
commit
02682da8eb
1 changed files with 19 additions and 3 deletions
|
|
@ -12,6 +12,9 @@ public class PlayerController : MonoBehaviour {
|
|||
public GameObject vvAura;
|
||||
public int swigCounter;
|
||||
private GameController gameController;
|
||||
public GameObject playerSprite;
|
||||
|
||||
enum Direction {Left, Right};
|
||||
|
||||
void Start() {
|
||||
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
|
||||
|
|
@ -29,6 +32,17 @@ public class PlayerController : MonoBehaviour {
|
|||
animator = GameObject.Find("PlayerSprite").GetComponent<Animator>();
|
||||
}
|
||||
|
||||
void MakePlayerSpriteFace(Direction dir)
|
||||
{
|
||||
Vector3 scaleVec = playerSprite.transform.localScale;
|
||||
if (dir == Direction.Left) {
|
||||
scaleVec.x = -1;
|
||||
} else if (dir == Direction.Right) {
|
||||
scaleVec.x = 1;
|
||||
}
|
||||
playerSprite.transform.localScale = scaleVec;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButton("Fire1") && Time.time > nextFire)
|
||||
|
|
@ -60,10 +74,12 @@ public class PlayerController : MonoBehaviour {
|
|||
|
||||
if (moveHorizontal < 0) {
|
||||
playerAngle.eulerAngles = new Vector3(0f, -180f, 0f);
|
||||
|
||||
MakePlayerSpriteFace(Direction.Left);
|
||||
}
|
||||
if (moveHorizontal > 0) {
|
||||
playerAngle.eulerAngles = new Vector3 (0f, 0f, 0f);
|
||||
MakePlayerSpriteFace(Direction.Right);
|
||||
}
|
||||
if (moveHorizontal > 0)
|
||||
playerAngle.eulerAngles = new Vector3(0f, 0f, 0f);
|
||||
if (moveVertical < 0)
|
||||
playerAngle.eulerAngles = new Vector3(0f, -270f, 0f);
|
||||
if (moveVertical > 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue