From 5e139c87e6cf867c840ebc2607d984b8e2d744e7 Mon Sep 17 00:00:00 2001 From: MartinRemi Date: Mon, 16 Nov 2015 17:42:52 -0500 Subject: [PATCH] Added life display --- Assets/CollisionCheck.cs | 10 +++++++++- Assets/Scripts/PlayerBehavior.cs | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Assets/CollisionCheck.cs b/Assets/CollisionCheck.cs index 0f7fd65..a652378 100644 --- a/Assets/CollisionCheck.cs +++ b/Assets/CollisionCheck.cs @@ -1,13 +1,21 @@ using UnityEngine; using System.Collections; +using UnityEngine.UI; public class CollisionCheck : MonoBehaviour { + public Text health; + + public void initText(int hp) + { + health.text = "Health: " + hp; + } + void OnCollisionEnter2D(Collision2D col) { if(col.gameObject.name == "Enemy") { - Debug.Log(gameObject.GetComponent().removeHP(1)); + health.text = "Health: " + gameObject.GetComponent().removeHP(1); } } } diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 976ee45..bcd5902 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -22,6 +22,7 @@ public class PlayerBehavior : MonoBehaviour { rb = gameObject.GetComponent(); anim = gameObject.GetComponent(); + gameObject.GetComponent().initText(gameObject.GetComponent().getHP()); } // Update is called once per frame