I am trying to make a top down shooter. I tried to make it so that when i touched a zombie, i took damage. It doesn’t show any errors. Why doesn’t it work?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class damage2 : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth;
public HealthBar healthBar;
// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
healthBar.SetMaxHealth(maxHealth);
}
// Update is called once per frame
private void Update()
{
if (Collision2D.Tag.Equals("zombie"))
{
TakeDamage(10);
}
void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
}
}
}