mirror of
https://github.com/ConjureETS/Labo_2_equ_2_a15.git
synced 2026-03-25 18:11:07 +00:00
Added life display
This commit is contained in:
parent
26030084ef
commit
5e139c87e6
@ -1,13 +1,21 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class CollisionCheck : MonoBehaviour {
|
public class CollisionCheck : MonoBehaviour {
|
||||||
|
|
||||||
|
public Text health;
|
||||||
|
|
||||||
|
public void initText(int hp)
|
||||||
|
{
|
||||||
|
health.text = "Health: " + hp;
|
||||||
|
}
|
||||||
|
|
||||||
void OnCollisionEnter2D(Collision2D col)
|
void OnCollisionEnter2D(Collision2D col)
|
||||||
{
|
{
|
||||||
if(col.gameObject.name == "Enemy")
|
if(col.gameObject.name == "Enemy")
|
||||||
{
|
{
|
||||||
Debug.Log(gameObject.GetComponent<Health>().removeHP(1));
|
health.text = "Health: " + gameObject.GetComponent<Health>().removeHP(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ public class PlayerBehavior : MonoBehaviour
|
|||||||
{
|
{
|
||||||
rb = gameObject.GetComponent<Rigidbody2D>();
|
rb = gameObject.GetComponent<Rigidbody2D>();
|
||||||
anim = gameObject.GetComponent<Animator>();
|
anim = gameObject.GetComponent<Animator>();
|
||||||
|
gameObject.GetComponent<CollisionCheck>().initText(gameObject.GetComponent<Health>().getHP());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user