Getting The Error
error: cs(30,32)CS1061: ‘Collider2D’ does not contain a definition for ‘GameObject’ and no accessible extension method ‘GameObject’ accepting a first argument of type ‘Collider2D’ could be found (are you missing a using directive or an assembly reference?)
I need help, I just don’t get why I’m getting this error. Here is the code, it is a script for my sword hitbox to damage the enemy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HurtEnemy : MonoBehaviour
{
public int damageToGive = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Enemy")
{
HealthManager eHealthMan;
eHealthMan = other.GameObject.GetComponent<HealthManager>();
eHealthMan.HurtEnemy(damageToGive);
}
}
}