Simple Battle System in Unity (Spawn Enemy Waves, Trigger)

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • 🌍 Download Dashlane for FREE on your first device by clicking here bit.ly/3ayHh83 and automatically get a 30 day free trial of premium! No credit card required at signup!
    ✅ Get the Project Files and Utilities at unitycodemonke...
    Let's make a Simple Battle System script to handle Spawning Enemy Waves with Events on Start and Finish.
    This video is sponsored by Dashlane
    I made a Top-Down Shooter in 7 Days!
    unitycodemonke...
    • I made a Top-Down Shoo...
    Animated Sprite Outline - Shader Graph
    • Sprite Outline (Animat...
    Aim at Mouse
    • Aim at Mouse in Unity ...
    Persistent Particle System
    • Persistent Particle Sy...
    Simple Key Door System
    • Simple Key Door System...
    If you have any questions post them in the comments and I'll do my best to answer them.
    🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
    See you next time!
    📍 Support on Patreon / unitycodemonkey
    🤖 Join the Community Discord / discord
    📦 Grab the Game Bundle at unitycodemonke...
    📝 Get the Code Monkey Utilities at unitycodemonke...
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonke...
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

КОМЕНТАРІ • 72

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 роки тому +10

    Here's the Battle System I used in the Top-Down Shooter game, how would you expand upon it?
    🌍 Get Dashlane for FREE on your first device by clicking here bit.ly/3ayHh83 and automatically get a 30 day free trial of premium! No credit card required at signup!
    👍 Downloading the app helps support the channel!

    • @melian5018
      @melian5018 10 місяців тому

      Hi Code Monkey! Thanks for the tutorial! But I have the following question - I tried to download your package, but failed to load all the script, particularly the Enemy Archer script so that I could refer to the Spawn method. Does your package only run on certain Unity versions? Sorry for the trouble >.

  • @aquaarmour4924
    @aquaarmour4924 4 роки тому +22

    Great job on the sponsor! I hope this will allow you to keep creating great content as always.

  • @Drifts3
    @Drifts3 4 роки тому +9

    your tutorials are amazing, very comprehensive. also always making sure to teach clean code, not just quick code. so much to aspire to! keep it up

    • @COLDoCLINCHER37
      @COLDoCLINCHER37 4 роки тому

      What's clean code? What are the benefits of such code.

  • @johnathanclaasen7996
    @johnathanclaasen7996 3 роки тому +2

    I just want to say thanks, your tutorials are awesome, im currently working on a VR project and this helped a lot. Keep em coming !

  • @r.f886
    @r.f886 3 роки тому

    Great Tutorial, in a few seconds i also learned alot about how state machines work :) Please keep up making good videos

  • @TheJishanator
    @TheJishanator 4 роки тому +7

    Would a nice way to maintain the waves from the battle system be making a scriptable object for them (holding an array of enemies' transforms and spawn time) and then assigning waves 1,2,3 to the array of waves on the system?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      Yup exactly, using a scriptable object instead of a simple array would be a great way to simplify the inputs as well as easily add more optional complexity to your spawning logic.

  • @JohnCrandell
    @JohnCrandell 4 роки тому +4

    Good evening,
    I have been watching this video and number of other ones, trying to get a good start on a build of the battle system you have designed here, this is all very impressive!
    The issue I am encountering is finding the start. In the video above, you gloss over the EnemySpawn script and the Spawn() function is mentioned, but never opened up. What video would I need to start with to really build this system from the ground up?
    What you have here is very much in line with what I want, I am working on a spawn system like that in the original Legend of Zelda, so that when you walk on screen, the enemies spawn, leave it, they are removed.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      It just calls Instantiate(enemyPrefab); which then plays the shader effect before enabling their AI.

    • @Moooxe
      @Moooxe 4 роки тому +1

      A bit late but yeah, I had the same doubt, I downloaded Code Monkey's unitypackage file and checked, it was a simple SetActive function, to enable the gameobject, inside a public function, so that it could be called from outside even when the gameobject was disabled. Quite clever, Thanks CodeMonkey, the tutorial really helped!

  • @bolenevolja
    @bolenevolja 4 роки тому +15

    Can you made tutorial for 3D games

    • @CodingJedi
      @CodingJedi 4 роки тому +1

      _ Bosko4Pro _ Hi, I’ll be covering 3D game tutorial .. I’ll be really happy if i can get some support :))

  • @andriibilych4983
    @andriibilych4983 4 роки тому

    Man you are a legend.

  • @jean-michel.houbre
    @jean-michel.houbre 4 роки тому

    Nice system. I love events!

  • @aggressivemastery
    @aggressivemastery 4 роки тому

    Awesome Stuff as always Code Monkey :)
    I am surprised that you are not using DOTS more regularly. Do you see it as just additional complexity for these tutorials, or are you seeing it not perform as well? Just curious?
    Of course, you ARE be the leading edge on DOTS tutorials. So I understand, its a bit harder :)
    Calling it a "Battle System" got me all excited... :P
    Cheers!
    Micah

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      I try to mix them both, I love DOTS but normal game objects aren't going anywhere so there's still lots of topics I'd like to cover. Currently working on DOTS Pathfinding so over time I will remake a bunch of systems in DOTS

  • @metkam5153
    @metkam5153 4 роки тому +3

    where is spawn script?

  • @Gunner3332
    @Gunner3332 4 роки тому +2

    I don’t know if you take suggestions but Could you do a system for gun variants like a system for guns with different stats

  • @MattJGames7
    @MattJGames7 6 місяців тому

    @CodeMonkeyUnity How did you make the "Charger Enemy" in this video, can you Make a 3D Tutorial on it Because I really want to have a Charger Enemy in my game but there are no tutorials on how to make one

  • @douglieberman9689
    @douglieberman9689 Рік тому

    Hey I created a shooting enemy and I tried to put multiple of them in the scene and they mess with each other especially when I disable/kill one of them
    how do I keep this from happening

  • @Marco-rv7ec
    @Marco-rv7ec 3 роки тому +2

    Why didnt you show the Spawn method in you enemies?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      How my specific enemy works isn't relevant to the Battle System logic, your enemies will certainly have some logic specific to your own game, it can be as simple as instantiating a prefab or more complex.

  • @A_cool_fish_from_France
    @A_cool_fish_from_France 3 роки тому +1

    I know this is late but will this work with 3d games as well?

  • @quanghong3922
    @quanghong3922 4 роки тому

    Good job

  • @walney2008
    @walney2008 4 роки тому

    I love your projects, would you have something teaching a quest system? attack as in WoW, where he marks the animal he attacks alone, would there be anything? and thank you I learn a lot with your videos, success

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      I haven't done a system to manage Quests but I have done the visual pointing to a target ua-cam.com/video/dHzeHh-3bp4/v-deo.html

    • @walney2008
      @walney2008 4 роки тому

      Hello, thank you very much, I would have something or could teach you how to make this game mechanic like DDTANK, where we put strength, and show the angle and try to hit the other, I lowered your bird with an example of strength, more to the angle how to show or appear a marker on the screen where the shot can go, other types of shots, here’s the suggestion, today I’ll download more examples for studies, thanks

  • @petrhampl7761
    @petrhampl7761 3 роки тому

    Great video! I have 1 question how do you prevent that enemies wont spawn in objects in levels. In my game they get stuck at stone or other stuff

  • @457Deniz457
    @457Deniz457 4 роки тому

    Reeeaaaally really nice, #thanks ! :)

  • @AidinZolghadr
    @AidinZolghadr 4 роки тому

    Hi Hugi, how do you suggest to make enemy AI for games? I know FSM's but A) I don't know a good implementation in Unity that is not too complicated (and hopefully has visual diagrams) and B) Be extensible to let me make and iterate enemies fast. Thanks!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      I covered a simple AI System here ua-cam.com/video/db0KWYaWfeM/v-deo.html
      Everything I've done in all my games is just expanded upon that

  • @TheYouPoop
    @TheYouPoop 3 роки тому

    5:38 is so funny to me

  • @SaSeshen
    @SaSeshen 3 роки тому

    I am curious, and hopefully you or anyone else can answer the question, but what is the difference between Private and Public void in the function? I have seen several tutorials on various aspects of scripting mechanics for a game and I am unclear as to the purpose of one over the other?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      private means that function/field can only be accessed from that same class.
      public means any class in your entire codebase can access it

  • @mayankbhaisora2699
    @mayankbhaisora2699 2 роки тому

    Clutch at 15:45

  • @moisinn5070
    @moisinn5070 4 роки тому

    Hi dude! fantastic tutorial! been looking into getting into event handling... one issue i have and i cant seem to get my head around is that when you place your Array. you are able to select different enemys . i realised that they are of the same type (enemy spawn), how is it that you make that three different types enemys are accesable from the same script?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      Either use Interfaces or a Base class that they all share.

  • @sikandarkumar7563
    @sikandarkumar7563 4 роки тому +1

    When I will start game development to which I will make game firstly 2d or 3d

    • @Geek2002
      @Geek2002 4 роки тому +1

      Also when making a 3D game you have to worry about modelling, texturing and lighting where as with a 2d game you can just draw the graphics in photoshop or something similar

    • @sikandarkumar7563
      @sikandarkumar7563 4 роки тому

      Thank you for your suggestions guys

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +2

      Yes unless you are already very experienced at 3D Modelling and Texturing then sticking with 2D will be easier

  • @juanb6570
    @juanb6570 2 роки тому

    i wanted to know how does this spawn system works, i'm working on a space shooter game, similar to games like R-type, and upon seeing how the enemies start hidden and then actually spawn i thought it could work for me

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому

      It just instantiating the prefab. You mean hte visual? It's a dissolve shader ua-cam.com/video/auglNRLM944/v-deo.html

  • @Irategamefan
    @Irategamefan 4 роки тому

    So my question is kinda weird but could you use this to make like a spawn system where the player has to kill like a Key amount of enemies on a mission? Like make your wave system and add more then enough for the player to get the mission ending code?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      Sure, this system is just a base, you can add whatever logic you want on top of it

  • @davekene
    @davekene 3 роки тому

    Hello,
    If the timer in the second wave is still counting and all the enemies in the first wave are dead, how can I automatically make the second wave spawn enemies so that the player doesn’t keep waiting.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому

      Keep track of when hte enemies die and add a function on the battle system to manually force start the next wave

  • @lennyseed9255
    @lennyseed9255 3 роки тому

    @ codemonkey is there a was of spawning enemies without turning the enemies in to a prefab, I actually made the enemy ai from the enemy ai video, and if I make the enemy component to a prefab all my references are rendered useless, dont know why

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +1

      You're probably losing references because you're trying to reference something in the scene, you cannot do that since the prefab can be instantiated in any scene.
      Structure your logic in such a way that either the prefab has all references as other objects or make your script grab those references when it initializes.

    • @lennyseed9255
      @lennyseed9255 3 роки тому

      @@CodeMonkeyUnity I am not understanding what u mean

  • @jv9ufxcy
    @jv9ufxcy 4 роки тому

    If instead of a timer to spawn the next wave, I wanted to check if the previous wave's enemies had all been killed, what should I use to check for that?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому +1

      Keep a list of all the enemies and when one of them dies go through the list and see if all are dead.

    • @jv9ufxcy
      @jv9ufxcy 4 роки тому

      @@CodeMonkeyUnity Thank you for the reply but I'm not sure how to apply that in the foreach loop that spawns the next wave. Would I be creating a list of Waves that remove themselves from that list when all the enemies in that wave return dead, stopping the loop when >1 wave is active?

    • @jv9ufxcy
      @jv9ufxcy 4 роки тому +2

      Ah I found a much better solution while going through that
      foreach (Wave wave in waveArray)
      {
      wave.Update();
      if (wave.IsWaveOver()) continue;
      else break;
      }

    • @rafcon9141
      @rafcon9141 4 роки тому +2

      @@jv9ufxcy Could u please show mevyour entire code. I'm trying to do the same thing.

  • @linpipilin9837
    @linpipilin9837 3 роки тому +1

    video is good, but just too hard to follow everything, you make all parts so hard to trace ~~~by watching this video, i dont know where to get EventHandle, and how Player player = collider.getcomponent(); , its just feel like everything havent say before suddenly appear and that makes the video very hard to follow up.
    by looking back other video will make it easier but , may be get some time to clear up the video list and make it like part 1 , 2 , 3 , 4 to make people who watch the video easier to follow and trace what they are doing.
    no offense by the way, its always so happy to watch your video and learn a lot from it. it just something about managing video , just like your code is well managed , but not the videos:)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 роки тому +1

      EventHandler is a standard C# class, if you don't know about events watch this video ua-cam.com/video/OuZrhykVytg/v-deo.html
      GetComponent(); is how you get a component in Unity, if you don't know about that then it sounds like you need to learn the absolute basics first before attempting to do a more complex system like this one ua-cam.com/video/E6A4WvsDeLE/v-deo.html
      Don't worry about how long it takes you or how much you need to rewatch something, that's all part of the learning process so just focus on learning and keep at it!

    • @linpipilin9837
      @linpipilin9837 3 роки тому

      @@CodeMonkeyUnity nice!! thank you for that, and which video is talking about how to make character from sprite ? i cant find any, most video already has character set up.

  • @thamihallami680
    @thamihallami680 4 роки тому

    Can you please recommande some books for unity C# programmation

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      The books that I recommend aren't strictly about C#, check out Clean Code and Code Complete
      ua-cam.com/video/Vlcop0uxFIQ/v-deo.html

  • @lem.
    @lem. 4 роки тому

    Hey dude you can do a MOBA game like lol offline or online, you know if you see this please do that video if you want :D bye

  • @SERBIANUGANDANKNUCKLES
    @SERBIANUGANDANKNUCKLES 2 роки тому

    4:47 How to know to add those codes in that archer or any enemy becouse i am new.. sry

  • @justsomerandomdude9783
    @justsomerandomdude9783 4 роки тому

    Can you make a enemy that spawn more enemy ?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      Sure, you can do whatever logic you want. In that case just instantiate an enemy prefab when one dies.

  • @devnulldevrandom6284
    @devnulldevrandom6284 4 роки тому

    Dashlane: SECURITY!!!!
    Dashlane: Compromises someones full CC info
    Hope it's fake lol

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 роки тому

      Are you saying Dashlane compromised someones CC info? Where did you hear that? I've done extensive research and found no such thing, it would take the lifetime of the universe to decrypt their data.

    • @devnulldevrandom6284
      @devnulldevrandom6284 4 роки тому

      @@CodeMonkeyUnity lol c'mon it's in video 1:58
      Hoping it's fake, but who knows..;)