mirror of
https://github.com/ConjureETS/Labo_2_equ_2_a15.git
synced 2026-03-24 01:21:07 +00:00
44 lines
770 B
C#
44 lines
770 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
|
|
public class CollisionCheck : MonoBehaviour {
|
|
|
|
//[HideInInspector]
|
|
public Text health;
|
|
|
|
|
|
public void initText(int hp)
|
|
{
|
|
health.text = "Health: " + hp;
|
|
}
|
|
|
|
void OnCollisionEnter2D(Collision2D col)
|
|
{
|
|
if(col.gameObject.name == "Enemy")
|
|
{
|
|
health.text = "Health: " + gameObject.GetComponent<Health>().removeHP(1);
|
|
}
|
|
|
|
|
|
|
|
if(gameObject.GetComponent<Health>().getHP() == 0)
|
|
{
|
|
gameObject.GetComponent<PlayerBehavior>().Death();
|
|
}
|
|
}
|
|
|
|
void OnTriggerEnter2D(Collider2D col)
|
|
{
|
|
if(col.tag == "Player")
|
|
{
|
|
|
|
health.text = "Health: " + gameObject.GetComponent<Health>().addHP(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|