How do I make GameObject deal damage to player?,How do I make a Game Object deal damage to player when they collide?

I recently added Brackey’s health bar into my game. I wanted to change from pressing a button to show damage to having an enemy’s projectile deal damage.

These are the line of code I want to change.

if (Input.GetKeyDown(KeyCode.Space))
{
TakeDamage(20);
}

(I’m new to coding… excuse my noob like behavior),I recently added Brackey’s health bar to my game, I was wonder how I could make one of my enemy projectile damage the player. instead of pressing a button.

I’m looking to replace this

if (Input.GetKeyDown(KeyCode.Space))
{
TakeDamage(20);
}

But I think this answer I gave, should help put you on the right path:

https://answers.unity.com/questions/1913392/how-to-use-a-trigger-from-a-called-gameobject.html?childToView=1913558#answer-1913558

But instead of it being trigger enter, you would be looking for void OnCollisionEnter(Collision other)