Am assuming you want an enemy to automatically shoot a player when they come close to them.
All you need is to check whether the player is close to the enemy then shoot.
Add a variable in your enemy's script to store the players position:
This variable is to be updated in the _process method of the level where you are spawning the enemies as follows:
enemy.player_position = $Player.global_position
Use add this method in the enemy's script to check whether the player is close enough:
return get_global_position.distance_to(player_position) < 300
In the enemy's script _process method, add:
All you need now is to add the
shoot() method like @Tato64 has illustrated.