Create a Reusable Health System (Unity Tutorial | 2D Top Down Shooter)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ต.ค. 2024

ความคิดเห็น • 24

  • @sanake2636
    @sanake2636 7 วันที่ผ่านมา

    thanks for the video. i'm not sure how would you use the healthcontroller for the enemies, could you explain more?

  • @HalcyonVoid
    @HalcyonVoid ปีที่แล้ว +3

    Looking forward to the UI portion. Ive been needing exactly that kind of logic for a bit and your clarity will really help.

  • @glebiank
    @glebiank 9 หลายเดือนก่อน +1

    Why are we using IsInvincible property instead of a public field? Both get and set methods are public, so we don't need a property, which is used for separation for public get-method and private set-method. And if both are private or public we just use a field instead of a property. Or is it a kind of common approach for OOP to use properties instead of fields when using their info in another class?
    Also, IDK the further development of the HealthController script, but I suggest the following definition for the TakeDamage method:
    public void TakeDamage(float damage)
    {
    if (IsInvincible)
    {
    return;
    }
    currentHealth = (currentHealth - damage) < 0 ? 0 : currentHealth - damage;
    if (currentHealth == 0)
    {
    OnDied.Invoke();
    }
    else
    {
    OnDamaged.Invoke();
    }
    }
    There are minor changes which help us to avoid repetative if-checks for 'equal to zero'

    • @KetraGames
      @KetraGames  9 หลายเดือนก่อน

      Hi
      Using a public field would work fine. This would then show in the Inspector in Unity though and you would be able to change the value from there. You could hide it though by adding the [HideInInspector] attribute.
      The main reason we went with a property is it is generally seen as best practice in C# to use properties to provide external access. The main advantages of properties over public fields in general C# programming are
      - Control over data access
      - Being able to include on an interface
      - Logic in the get/set methods
      - Easier debugging
      In this scenario the only one that really applies is the easier debugging. You can put a breakpoint on the get/set of the property to debug when it is being accessed.
      Hope that helps 😊

    • @KetraGames
      @KetraGames  9 หลายเดือนก่อน

      Also, thanks for the suggested refactoring 😊

  • @mrgoodkat1135
    @mrgoodkat1135 9 หลายเดือนก่อน +1

    Greetings! Thank you for your videos very much! Tell me, if 4 enemies are attacking at the same time, why is damage inflicted only from 1 enemy every 3 seconds?

    • @KetraGames
      @KetraGames  9 หลายเดือนก่อน +1

      Thanks 😊
      The reason there is only damage every 3 seconds is because the player has 3 seconds of invincibility after being hit. If you wanted to take damage from multiple enemies at the same time then you could switch it around so each enemy inflicts damage periodically and there is a delay after each attack to stop the health draining too quickly. Hope that helps 😊

    • @mrgoodkat1135
      @mrgoodkat1135 9 หลายเดือนก่อน

      @@KetraGames Thanks! You best!

  • @TaylorCoffman87
    @TaylorCoffman87 ปีที่แล้ว +3

    These have been amazing, my first set of tutorials!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Great to hear this, thanks 😊

  • @muffinman999
    @muffinman999 ปีที่แล้ว +3

    Love these tutorials. Thank you 🙏

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for this comment 😊

  • @solid9643
    @solid9643 ปีที่แล้ว +1

    Hello, I have a question about the 3D platform series, When walking around with the player it only moves at 0.1 speed and when I jump and move it moves regularly, I also noticed that the player movement settings like setting the jump height for the player *5* for speed is not there to set it to a specific number. If you can please help me with this issue I would greatly appreciate it

    • @KetraGames
      @KetraGames  ปีที่แล้ว +2

      Hi, when walking/running are you using root motion? If you are then it will move as fast as the animation. In the animator you can increase the speed of the animations if you need to.

  • @furukhai
    @furukhai ปีที่แล้ว +2

    I love your accent 😄

  • @user-ki1bx7dp5k
    @user-ki1bx7dp5k หลายเดือนก่อน

    Thanks for the tutorial. I have followed all previous videos in this series, however I've used different sprite assets and a custom area for the Polygon Collider 2D (to match the sprites i'm using). I am unable to get the invincibility to work, no matter what duration I set. The enemies still kill the player really quickly (with seemingly no invincibility working!). I've copy/pasted the scripts provided but still doesn't seem to work. I'm guessing this could be due to the custom area for the collider? But not sure where I'm going wrong!

    • @KetraGames
      @KetraGames  หลายเดือนก่อน

      Hi, the different collider shouldn't cause a problem. If you've copied the script then it's likely something missing in the Unity inspector. Could you double check you have the handler added to the damaged event of the player HealthController to activate the invincibility?

    • @user-ki1bx7dp5k
      @user-ki1bx7dp5k หลายเดือนก่อน

      @@KetraGames Yes I have readded it and still have the same issue

  • @gazzer4461
    @gazzer4461 ปีที่แล้ว +1

    Thanks Ketra. That sounds really useful!

  • @anthonysarkis6032
    @anthonysarkis6032 ปีที่แล้ว

    How to kill the enemies when bullets touch them?

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Hi, shooting is covered in this video th-cam.com/video/JcfNFoeuzUk/w-d-xo.html