Help with making a script for a 2d platformer enemy

So I’ve just gotten into playing around with unity and started creating my own platformer, but now I need to make a script for my enemy that can detect when the player is near and attack the player and play an animation. I would appreciate any ideas or solutions that could help me reach this goal.

You can use Raycast to detect the player.

You can use other casts if they suit your tastes better than a regular Raycast: