I have also tried making a samll overlap area around the 2D collider but that didn't work out
here is the script`
using UnityEngine;
using System.Collections;
public class hELT : MonoBehaviour
{
public int currentHealth = 5;
public int maxHealth = 5;
void Start() {
}
void Update() {
if (currentHealth > maxHealth) {
currentHealth = maxHealth;
}
if (currentHealth <= 0) {
currentHealth = 0;
Die();
}
}
void Die() {
Destroy(gameObject);
}
void TakeDamage(int damage)
{
currentHealth -= damage;
}
void OnColliderEnter(Collider other)
{
if (other.tag == "Enemy")
{
TakeDamage(5);
}
}
}
`
↧