How to code a basic enemy AI script?

The type of game I’m trying to make is one where you’re sitting in a bunker while enemies are infinitely spawning and shooting at you. All I want them to do is approach the bunker to a certain point and fire their weapons. I know next to nothing about coding right now so if anyone could give me an example of a script where the enemies approach you and start shooting when they get to a certain point, that would be much appreciated. Thanks.

Being able to break down problems into smaller sized chunks you can quickly look up is a critical ability in game development (and most other kinds of engineering). You want to dive into topics around:

  • How to instantiate objects?
  • How to randomize positions (and timings) for the spawning?
  • How to make the ai walk / run towards a point (or use pathfinding)?
  • How to make the ai shoot?
  • Damaging the player, HP, …?

For all of these there are tons of tutorials. In order to combine them as you imagine it you will have to understand these topics tho. But that’s always the case. Sadly you wont ever find a 1:1 solution for exactly what you need, unless that thing was trivial to begin with. You will find bits and pieces you can take (or learn from) and will then have to puzzle them together and integrate them into something new that fits your specification.

You wrote you are new to coding, which is fine. If you are here to learn programming and game development i would however suggest starting with one of the better tutorial series out there to teach you the ropes, instead of jumping into some project with no background whatsoever and trying to copy code you dont understand to make things work. Personally i usually recommend Sebastian Lagues gamedev tutorial series. He starts at absolutely 0 knowledge and covers anything from useful programming concepts, to C# and the Unity Engine itself. He also offers little exercises for you to solve, it’s really well made imho.

(If, on the other hand, you dont want to learn coding and just want or need this project done, for example as a prototype, i suggest hiring someone to do it for you. We have a forum for that as well, and there exists third party websites where people offer services such as this aswell.)