How to Make A Simple HEALTH SYSTEM in Unity

Описание к видео How to Make A Simple HEALTH SYSTEM in Unity

🍍 In this Unity Tutorial we'll be setting up the absolute basic essentials for a generic Health script which will allow of us to set a Max Health and Take Damage as well as Heal.

The Health script can be used on Players, Enemies, GameObjects, whatever you want!

This is a follow up to the Health Bar Tutorial (link below) I've done in the past, as there were more than a few comments about how to setup a Player Health Script.

I figured this would be a good opportunity to showcase that. Since people we're struggling to get a relatively simple script setup themselves, I didn't want to go too far into adding more features to the health script and risk the tutorial becoming too complex.

With that said, PLEASE COMMENT if you have something in particular you'd like me to cover, I'd be happy to make a video on it.

Link to HEALTH BAR tutorial:    • HEALTH BAR Unity UI Tutorial (Beginne...  

Link to Damage Popup tutorial:    • Floating Text in Unity  

✨Want to support the channel?
Buy me a coffee ☕: https://ko-fi.com/bmoli

➤Join our DISCORD SERVER:   / discord  
We have channels to help you with your problems!

➤SUBSCRIBE to learn more game dev

Summary

To setup a health script is rather simple. We just need to track 1-2 variables. MaxHealth and CurrentHealth. These can be integers or floats or whatever datatype you prefer.

As a good rule of thumb I like to set my CurrentHealth = MaxHealth in my Start method, as this makes it convenient when testing in Play mode.

For TakeDamage we simply need to subtract a damage amount you determine from our "CurrentHealth" variable. We then add a check if the CurrentHealth is less-than-or-equal-to 0, in which case...we're dead ☠

For Healing, the opposite occurs, we add to our CurrentHealth an amount you determine. We then check to see if its greater-than our MaxHealth, and if it is, we set CurrentHealth = MaxHealth to cap it. This step isn't needed if you do not have a MaxHealth in your game.

That is basically it! You can now use this script and add to it to spice it up by using Health Bars, Animations, Particles, Effects, Sounds, etc.

Thanks for watching!

#bmo #unity #tutorial

Комментарии

Информация по комментариям в разработке