Commit f4eb9b16 authored by Domm29's avatar Domm29
Browse files

Merge branch 'mergeTemp'

# Conflicts:
#	.idea/.idea.seedling/.idea/contentModel.xml
#	.idea/.idea.seedling/.idea/workspace.xml
#	Assets/Prefabs/player.prefab
#	ProjectSettings/TagManager.asset
parents d5953702 2c4ad23a
This diff is collapsed.
...@@ -5,8 +5,9 @@ using UnityEngine; ...@@ -5,8 +5,9 @@ using UnityEngine;
public class Life : MonoBehaviour public class Life : MonoBehaviour
{ {
private int life;
public int life; public GameObject hud;// The Hud with the Health Bar
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
...@@ -21,9 +22,13 @@ public class Life : MonoBehaviour ...@@ -21,9 +22,13 @@ public class Life : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other) private void OnCollisionEnter2D(Collision2D other)
{ {
//Layer 30 is the Damage Hazad and 31 is Damage Enemy
if (other.gameObject.layer == 30 || other.gameObject.layer == 31) if (other.gameObject.layer == 30 || other.gameObject.layer == 31)
{ {
life--; life--;
hud.GetComponent<UI_Health>().LifeLost(life);
} }
} }
} }
...@@ -11,6 +11,7 @@ public class UI_Health : MonoBehaviour ...@@ -11,6 +11,7 @@ public class UI_Health : MonoBehaviour
public Image leaf3; public Image leaf3;
public GameObject playerObject; public GameObject playerObject;
private GameObject hudCanvas; private GameObject hudCanvas;
private void Awake() private void Awake()
{ {
...@@ -26,30 +27,35 @@ public class UI_Health : MonoBehaviour ...@@ -26,30 +27,35 @@ public class UI_Health : MonoBehaviour
private void Update() private void Update()
{ {
if (playerObject.GetComponent<Life>().life == 3)
{ }
leaf1.enabled = true;
leaf2.enabled = true; public void LifeLost(int lifeOfPlayer)
leaf3.enabled = true; {
} switch (lifeOfPlayer)
else if (playerObject.GetComponent<Life>().life == 2)
{
leaf1.enabled = true;
leaf2.enabled = true;
leaf3.enabled = false;
}
else if (playerObject.GetComponent<Life>().life == 1)
{
leaf1.enabled = true;
leaf2.enabled = false;
leaf3.enabled = false;
}
else if (playerObject.GetComponent<Life>().life <= 0)
{ {
leaf1.enabled = false; case 3:
leaf2.enabled = false; leaf1.enabled = true;
leaf3.enabled = false; leaf2.enabled = true;
hudCanvas.GetComponent<UI_SceneManager>().ReloadScene(); leaf3.enabled = true;
break;
case 2:
leaf1.enabled = true;
leaf2.enabled = true;
leaf3.enabled = false;
break;
case 1:
leaf1.enabled = true;
leaf2.enabled = false;
leaf3.enabled = false;
break;
default:
leaf1.enabled = false;
leaf2.enabled = false;
leaf3.enabled = false;
hudCanvas.GetComponent<UI_SceneManager>().ReloadScene();
break;
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment