How To DAMAGE Enemies in Unity

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 64

  • @T3QN1Q
    @T3QN1Q 2 года назад +3

    based on your other recent video, "the four gamer personality types" (great vid btw) I know I'm a killer so this is what I need!

  • @thenoglinman
    @thenoglinman 2 года назад +1

    I was just about to look for an enemy damage tutorial then got this notification!

  • @HunneProductions
    @HunneProductions Год назад +5

    For some reason "ToList()" in the GameManager script isnt working. Do you know why?

  • @sharkao2686
    @sharkao2686 2 года назад +7

    private void Awake()
    {
    enemies = GameObject.FindObjectsOfType().ToList();
    UpdateEnemiesLeftText();
    }
    its giving me an error in the ToList() and the error says this Enemy[]' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'Enemy[]' could be found (are you missing a using directive or an assembly reference?)

    • @ryanmac8984
      @ryanmac8984 2 года назад +1

      I'm not sure if this is wrong somehow, but adding "using System.Linq;" in the top of your script seems to solve this issue.

    • @cryptolotl
      @cryptolotl 2 года назад

      Tried adding the using System.Linq; but still get the same error. Also tried adding using UnityEngine.UI; but still shows up. Anyone else resolve the issue a different way, or has the System.Linq worked for everyone else?

    • @Moneybefehl
      @Moneybefehl Год назад

      @@cryptolotl im running into the same problem, ill update if i find a solution

    • @Moneybefehl
      @Moneybefehl Год назад

      @@cryptolotl so my solution is:
      private void Awake()
      {
      enemies = new List();
      enemies.Add(GameObject.FindObjectOfType());
      }
      we first instantiate enemies with an empty list of type Enemy and then add the Enemy object

    • @HunneProductions
      @HunneProductions Год назад

      it works

  • @plutoniumbellamy1912
    @plutoniumbellamy1912 2 года назад +6

    Could you make a tutorial about an ammo collection system. Say, an ammo randomly drops after a certain event occurs, then when the player collects/collides with it - it serves as an ammo for a shooting system to the enemy(s). When the ammo counter is 0, then the play can't shoot, and so on. Thanks!

  • @michaelonuoha6548
    @michaelonuoha6548 Год назад +1

    thank you sir you saved my entire life i havent slept since

  • @bacjam6139
    @bacjam6139 2 года назад +3

    Tutorials like this are life savers

  • @i_am_set
    @i_am_set 2 года назад +1

    You are easily one of my favorite Unity tutorial youtubers!

  • @torontogamestudio2991
    @torontogamestudio2991 2 года назад +2

    Can you make a tutorial on how the next scene will load after all enemies are killed?

  • @Joriku
    @Joriku Год назад +1

    Thank you, took me hours to even get something to work. This got me able to shoot my current test enemy without issues

  • @MaestroMarc
    @MaestroMarc 3 месяца назад

    It'd be neat if you made a 3D version of this tutorial!

  • @LuanaSouza-fw1iz
    @LuanaSouza-fw1iz 2 года назад +1

    It was nice to see a mix of direct calling a function in an script and c# events on the same structure.
    Also, when I subscribe event's on the awake/enable function it seems like many of the events are called before they are created. That's why I subscribe on start lately. Did that ever happened to you? I find subscribing on enabled and unsubscribe on disabled elegant but couldn't do reliably

    • @BMoDev
      @BMoDev  2 года назад

      Yes, I know what youre talking about, it has to do with the order of scripts being executed - in which case the quick and dirty solution is the reorder things in your hierarchy, but you can specify which scripts execute first in the project settings menu, this way you create events first before subscribing

  • @Stompin40
    @Stompin40 2 года назад +2

    Holy sh*t this was sick to see!

  • @monkeypwners
    @monkeypwners Месяц назад

    My bullets go straight through my walls... I have a BoxCollider2D on the walls and on my bullet and none of them are set to "IsTrigger"... Please help

  • @saishsawant7410
    @saishsawant7410 2 года назад

    wow , i was struggling with enemy destroy for so long., all the other videos were of no help ... i typed your code and a few tweak's and the code was working fine.

  • @DashzRight
    @DashzRight Год назад

    Why the collisionEnter function is used in the projectile and not in the enemy?

  • @jrgvsgames5673
    @jrgvsgames5673 Год назад

    So i followed everything correctly but when i shoot my enemy it doesnt die? any help please?

  • @WladylawGomulka
    @WladylawGomulka Год назад

    what if i have couple enemy prefabs each named diffrently?

  • @cank4286
    @cank4286 2 года назад

    C# static events FTW! Unity Events and messaging suck :( . Only issue is += -= syntax is weird and causes noisy code.

  • @iken_ar
    @iken_ar 2 года назад

    Thanks !

  • @BlueAndy_
    @BlueAndy_ 2 года назад

    Well it doesnt quite work for me, i try this exact code just in 3d and insted to check the TryGetComponent thing for an normal collison i look if my RayCast has hit an Enemy and then try to use the public TakeDamage Funcion. And it does work for the very original Enemy but not for the other clones, even if i hit the clones the original enemy dies all of the time. Idk what is wrong here really confussing.

    • @BlueAndy_
      @BlueAndy_ 2 года назад

      Nevermind got it working, the only thing that i really did was assign an empty GameObject in the script name gameObjectHit and then just assined the GameObject that im hitting to this empty hitgameObject. And then i did what he in the Video did
      //this is on top of the code
      GameObject gameObjectHit;
      // this is inside the if statement when the raycast hit something
      gameObjectHit = hitInfo.transform.gameObject;
      if(gameObjectHit.TryGetComponent(out HitDetection en))
      {
      en.TakeDamage(damage);
      }

  • @Unknownuncovered-NIKI7
    @Unknownuncovered-NIKI7 6 месяцев назад

    broo You forgot the bullet part!!!!

  • @noside6817
    @noside6817 2 года назад

    ty king

  • @ryanem969
    @ryanem969 2 года назад +1

    I've followed this tutorial from scratch, 3 times.
    My bullets do not "destroy"
    My bullets do no damage to enemy
    What could I be missing?
    EDIT: I had "OnCollision2D" not "OnCollisionEnter2D".
    Wow.

    • @6fukraken
      @6fukraken Год назад

      I have the same problem but i will just search other tutorial i guess

    • @ryanem969
      @ryanem969 Год назад

      @@6fukraken Oh, I was a noob. I'm not pro now but ask me anything.

  • @eggseatpegs
    @eggseatpegs 2 года назад +2

    Yeet

  • @noahnyman4420
    @noahnyman4420 2 года назад +1

    My enemies die in 1 shot :/
    update: I die in 1 shot :/

  • @tuxedobird8379
    @tuxedobird8379 Год назад +3

    i followed it but now y bullet just goes through everything i dont know what i did

    • @loozekh
      @loozekh Год назад

      same issue. if you find a fix please lmk
      update: go to your bullet prefab and disable istrigger on the collider, it'll work then

    • @6fukraken
      @6fukraken Год назад +1

      @@loozekh You have to add box collider (in the add component menu)

  • @tristanlapointe9087
    @tristanlapointe9087 2 года назад +5

    Wow thank you so much. I've never looked at basic stuff like this in such a complex yet modular and practical way. Great tutorial!

  • @travnutztv1578
    @travnutztv1578 Год назад +1

    Lost me at the game manager part. not sure if my "using"s are correct cause you never showed the top of the script.

  • @n11ckz64
    @n11ckz64 2 года назад +2

    Hey BMo! Can you make a tutorial about game mechanics like in "Move the block : Slide puzzle" game, please! There are no tutorials on this topic on the Internet. I will be very grateful if you make this tutorial!

  • @gnugget1015
    @gnugget1015 Год назад +1

    it says "'Enemy' does not contain a definition for 'TakeDamage' and no accessible extension method 'TakeDamage' accepting a first argument of type 'Enemy' could be found (are you missing a using directive or an assembly reference?)", even though I wrote all the code over four times!

  • @fryptompt
    @fryptompt Год назад +1

    I Have an enemy prefab and i am spawning that enemy with prefab now i have health system but the health Value is common for all of the enemies clone , how can i make the health value individual for all the clones ?

  • @fishyunlimited4033
    @fishyunlimited4033 5 часов назад

    did not work for me

  • @LesP56
    @LesP56 2 года назад +2

    How is this handled if the enemy is an instance of a prefab?

    • @BMoDev
      @BMoDev  2 года назад

      When you instantiate the prefab Start will get called, but you could create a FindTarget method and call that whenever you want or it will be called in Start if you put it there like the video.
      GameObject newEnemy = Instantiate(enemyPrefab);
      newEnemy.GetComponent().FindTarget();

  • @nickcapria817
    @nickcapria817 2 года назад +1

    .Count doesnt work for me any suggestions I get error CS0428

  • @eileeng2492
    @eileeng2492 2 года назад +1

    Who should I test this on first?

  • @fluffystuff
    @fluffystuff Год назад

    bruh I've been scouring the internet for this damaging player and this is the only tutorial that my tiny brain can understand (bcz I'm a beginner)

  • @zendraw3468
    @zendraw3468 Год назад

    why did you make the event in the enemies and not in the gamemanager? it shuld be the other way around

  • @Neon-no8kv
    @Neon-no8kv Год назад

    could you use this script as a player script too
    BTW great tutorial!

  • @taahaalbari
    @taahaalbari Год назад

    you are awesome! Thanks for the help & Great tutorial :D

  • @siickale
    @siickale 7 месяцев назад

    thanks for the tutorial

  • @qdnr
    @qdnr 2 года назад

    Спасибо

  • @contrabandest
    @contrabandest Год назад

    I want to have a Level Complete text when the enemy counter reaches zero. How would I do that with your script? I tried the if statement but dunno what to put in the brackets ( )

  • @godssilliestsoldier249
    @godssilliestsoldier249 2 года назад

    THIS is what i was looking for thanks

  • @bladeprincess
    @bladeprincess Год назад

    7:14 should the invoke line really be after the Destroy line? how is it called if the enemy is immediately destroyed? im curious and this would really help me. thanks!

    • @bradleypetzer6802
      @bradleypetzer6802 Год назад

      I'm also new to this but I believe I read recently that the Destroy action doesn't happen immediately so you are still able to call lines for a period after the Destroy. something to do with frames or updates
      Hope this helps. from a noob learning :)