Labo_2_equ_2_a15/Assets/Scripts/CollisionCheck.cs
JoelLapointe86 b4cc1dc6ce Trousse est maintenant fonctionnel
elle rend 3 pv
2015-12-01 21:04:07 -05:00

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);
}
}
}