Deal Damage On Collision

I am trying to make the player take damage when touching but i can’t. This is my code:
public void OnCollisionEnter()

{
if (GameObject.FindWithTag == (“Enemy”))

{
DealDamage(5);
}
}

OnCollisionEnter() requires parameters.

Something like

public void OnCollisionEnter(Collision col)
{
     if (col.gameObject.tag == "Enemy")
           //do stuff
}

As your code is written, you aren’t sending params to OnCollisionEnter, so it doesn’t have any reference, and you aren’t looking at tags for objects in the collision, you’re looking for ANY GO that has an Enemy tag.

FindWithTag is a function that looks through the whole scene to find an object with the specified tag, whereas if you’re trying to find if an object is touching another with a specific tag then you’ll want to use either CompareTag(“myTag”) or collider.gameObject.Tag == “myTag”.

void OnCollisionStay (Collision col) {
    if (col.compareTag("myTag") {
        DealDamage(5);
    }
}

Alternatively if you want to do it through entering a trigger then you can use:

    void onTriggerStay (Collider other) {
        if (other.compareTag("myTag") {
            DealDamage(5);
        }
    }

Thank you a lot!