Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
Tom H committed Jan 30, 2022
2 parents 427f775 + 76116cf commit ebd0427
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float speed = 1f;
Expand Down Expand Up @@ -32,7 +32,7 @@ void FixedUpdate()
{
health = health - Time.fixedDeltaTime * 1.5f;
//Debug.Log(health);
if(health < 0)
if (health < 0)
die();
Text textbox = GetComponentInChildren<Text>();
textbox.text = "Health: " + Mathf.RoundToInt(health).ToString() + "/100";
Expand All @@ -43,23 +43,28 @@ void OnMove(InputValue movementValue)
{
movement = movementValue.Get<Vector2>();

if(movement.magnitude > 0.1f)
if (movement.magnitude > 0.1f)
StartWalking();
else
StopWalking();

if (movement.y > 0f) {
if (movement.y > 0f)
{
transform.localScale = new Vector3(scale.x, scale.y, scale.z);
FaceDirection(Vector2.up);
}
else if (movement.y < 0f) {
else if (movement.y < 0f)
{
transform.localScale = new Vector3(scale.x, scale.y, scale.z);
FaceDirection(Vector2.down);
}
else if (movement.x > 0f) {
else if (movement.x > 0f)
{
transform.localScale = new Vector3(scale.x, scale.y, scale.z);
FaceDirection(Vector2.left);
} else if (movement.x < 0f) {
}
else if (movement.x < 0f)
{
transform.localScale = new Vector3(-scale.x, scale.y, scale.z);
FaceDirection(Vector2.left);
}
Expand All @@ -72,11 +77,15 @@ void FaceDirection(Vector2 direction)
front.SetActive(false);
back.SetActive(true);
side.SetActive(false);
} else if (direction == Vector2.down) {
}
else if (direction == Vector2.down)
{
front.SetActive(true);
back.SetActive(false);
side.SetActive(false);
} else {
}
else
{
front.SetActive(false);
back.SetActive(false);
side.SetActive(true);
Expand All @@ -97,20 +106,23 @@ void StopWalking()
side.GetComponent<Animator>().SetBool("Walking", false);
}

void die()
{
//Sets player status to dead
alive = false;
void die()
{
health = 0.0f;

Instantiate(deadPlayerPrefab, transform);
GetComponent<PlayerInput>().enabled = false;
front.SetActive(false);
back.SetActive(false);
side.SetActive(false);
//Sets player status to dead
alive = false;

Instantiate(deadPlayerPrefab, transform);
GetComponent<PlayerInput>().enabled = false;
front.SetActive(false);
back.SetActive(false);
side.SetActive(false);

//Pauses gameplay
Time.timeScale = 0;
}

//Pauses gameplay
Time.timeScale = 0;
}
void OnCollisionEnter2D(Collision2D other)
{
//Checks if other gameobject has a Tag of Player
Expand All @@ -123,5 +135,5 @@ void OnCollisionEnter2D(Collision2D other)
health = 100.0f;
}

}
}
}

0 comments on commit ebd0427

Please sign in to comment.