I’m trying to make it so that when i touch a zombie, I take damage.Why no 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
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag.Equals(“zombie”))
{
TakeDamage(10);
}
void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class damage : 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 (Input.GetKeyDown(KeyCode.Space))
{
TakeDamage(10);
}