How to get an enemy to go to a location and then return.

I’m creating a 2D top-down game and I want a certain type of enemy to come out of a hole to attack the player and then return when they miss the player. (The enemies are one shot killers.) I have a basic idea for what I want to happen, but I don’t know how to code it. I want the enemy to come out of hiding when the player reaches a certain area around it, head in the player’s direction, and then smoothly return to it’s hiding spot. I can’t find anything for coding this type of behavior.,

Good day.

You are asking different things. So go step by step.
Learn to do this things:

Create an object during runtime (Instantiate())

Move an Object to specific direction

Detect when 2 objects are closer than X distance

Make an object decide what to do depending on some variables (like the distance)

Create a bullet

Make the bullet to move to target

Make the bullet to kill or take health from the target

Destroy an object (die)

STEP BY STEP!

Once you control all of this, you only need to compile all togather in the correct order and configuration!

Good luck!