How to make a Health System | Unity Tutorial

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

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

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  4 года назад +22

    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php

    • @megozcreed5196
      @megozcreed5196 4 года назад

      Hey bro i found the tutorial very useful but i was wondering how to instansiate the healthbar as a child of the player and the enemies
      And distroy it when the health =0

    • @brooksaries4182
      @brooksaries4182 3 года назад

      i know Im randomly asking but does anybody know a trick to log back into an instagram account??
      I somehow lost my account password. I love any tricks you can offer me

    • @colemangael9720
      @colemangael9720 3 года назад

      @Brooks Aries Instablaster ;)

    • @brooksaries4182
      @brooksaries4182 3 года назад

      @Coleman Gael thanks so much for your reply. I got to the site on google and I'm trying it out atm.
      Looks like it's gonna take a while so I will reply here later with my results.

    • @brooksaries4182
      @brooksaries4182 3 года назад

      @Coleman Gael DAMN IT ACTUALLY WORKED :O I just hacked my IG password within roughly 40 minutes by using the site.
      Just had to pay 15 bucks but for sure worth it :O
      Thank you so much you saved my ass !

  • @umar7182
    @umar7182 6 лет назад +358

    You would get more views if you focus on explaining your code and take more time in it.
    You type really fast and are quite quick not very easy for beginners to learn stuff

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +26

      What specific part of the video did you find hard to understand?

    • @kohlisexclusive3847
      @kohlisexclusive3847 6 лет назад +4

      Please add // also for coder like us we know only c++ c we don't know header file using unityengine;
      Using codemonkey; is header file code monkey user defined or inbuilt

    • @theafricanking7141
      @theafricanking7141 6 лет назад +25

      Code Monkey just the while video in general, you don’t tell me what it does thoroughly and you type too fast for me to follow what the code does, don’t get me wrong it’s good but it would be better for beginners to maybe slow down but of course it’s ur channel so u do whatever u want but it’d be a bit easier for beginners to follow if u were slower.

    • @mithunchakravarthy6008
      @mithunchakravarthy6008 6 лет назад +3

      Same here why Debug.Log is being used? Maybe you have explained them in previous videos but I am new to your channel. If you have already explained why you've added certain code in earlier videos you could refer to them while you speak and post a link for em in the current videos description! Great job with the tutorial! Thanks a lot!

    • @thetnprogramer4268
      @thetnprogramer4268 6 лет назад +4

      Debug.Log is used to display some information in the console and in this case it displays the health

  • @SaltAndPepper.4U
    @SaltAndPepper.4U 6 лет назад +77

    The tutorials were excellent. But as a learner, I had hard time to follow or to catch up with your speed. I have done coding and I understand coding but as I am new to unity, I didn't get why did you do that step. I felt like I am supposed to know the unity already and should have game coding experience in unity. If there would have been an explanation for lines of code, you wrote, about why are we doing this then it would have been easy for me to follow. I understand that I lagg in unity undersatnding. ANyways, thanks for the tutorials.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +14

      If you have any specific question please to post it and I'll do my best to answer. The videos do assume a certain background in Unity and C#, I'm planning on doing some more beginner focused videos soon.
      In the newer videos I have made an effort to try and explain every single line of code before testing so check those out and see if they're easier to follow.
      Thanks!

    • @SaltAndPepper.4U
      @SaltAndPepper.4U 6 лет назад +2

      Thanks :)

  • @rameshtripathy8070
    @rameshtripathy8070 4 года назад +13

    Getting a code monkey ad on code monkey's video
    Code monkey: Stonks

    • @bharathball
      @bharathball 3 года назад

      thats like they are paying and getting it at the same time

  • @zovo9302
    @zovo9302 6 лет назад +59

    I got an ad about your video on another video xd

  • @driverjust4156
    @driverjust4156 4 года назад +13

    10:18 "making a Prefab out of HeathBar object"
    Just a bit of an explanation how to do it in "Unity 2018.3" (and newer): there is no need to create an empty Prefab through menu Create->Prefab (basically there is no such option now). You just grab an object HealthBar and drag-and-drop it to the Asset/Prefab folder.

  • @MassaCreto
    @MassaCreto 5 лет назад +16

    Loved the video... Although it is a speedy walk through, I do like how clean and thought out the code is... In my humble beginner opinion... :) Great stuff Sir...

  • @aseemudgirkar7233
    @aseemudgirkar7233 3 года назад +1

    Sorry I’m asking so many questions, but for some reason your CMDebug is not working. It won’t show up. I tried making it so that if you press a key it would take damage and heal, but that also didn’t work. Help needed

  • @ElniRael
    @ElniRael 5 лет назад +8

    amazing tutorials! the speed and explanations are awesome, u did a good job! for a unity noob like me it's just the right stuff to learn on. keep up!

  • @TheDeiphoboz
    @TheDeiphoboz 5 лет назад +4

    This is perfect and a very simple and tidy tutorial, I like that you introduce every watcher to a number of possibly new things compared to how a lot of tutorials are out there. They usually make scripts that is a one of, which works for a simple game having a couple mechanics. This is more usuable if you want to build on top of it. And the decoupling is very nice to see. It does take more from the usual tutorial watcher, but thats good imo.
    I used Unity UI which im not sure how works when it comes to optimization, you say its quite costly, and I might have to change this later on. I thought they were priced almost the same as a normal game object in the scene. The other thing about UI is that you need more code to support it, hiding it etc if you dont want it in view at all times.
    I added a UI anchor script for the HPbar script and just passed the transform from the game object that spawns it into the SetupBar(HPsystem, Transform) and set the "follow" to that transform.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      Glad you liked the video!
      If you do it in the UI but you want it following a unit in the world then you'll have to do viewpoint calculations on every single frame.
      It's not an issue if you just have one character but if you have hundreds like in an RTS then all those calculations will start to hit your performance.

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

    This is where everything began.

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

      It's been a long journey! Thanks for being here!

  • @steveag8018
    @steveag8018 5 лет назад +2

    Bro, your videos are pretty amazing. I am new to the UNITY and your videos literally can explain me clearly.
    Your are the best bro.
    I am expecting the new videos from u.

  • @jacobburt5424
    @jacobburt5424 3 года назад +1

    Im trying to make a game during my spring break. This vid helped me out a lot. Thanks bro I appreciate it.

  • @chrisdk5665
    @chrisdk5665 4 года назад

    Stay away if you’re absolute beginner, you will learn nothing but how fast this guy can type

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      You can pause the video at any time if you want to follow along. Where did you get lost?

    • @chrisdk5665
      @chrisdk5665 4 года назад

      @@CodeMonkeyUnity the whole vid bud. pausing doesnt explain why you do what you do. Simply copying isnt learning. Not for total beginners anyway.This channel is more aimed at people with some sort of knowledge for C#. Not bashing your channel just saying you'll be talking a foreign language to newbies

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      @@chrisdk5665 Yeah the videos all require some base of knowledge depending on the topic, some are for complete beginners and some require some basic knowledge of Unity and C#.
      This was my very first video and I've improved massively at explaining everything I do, check out my more recent videos.

  • @LarS22730
    @LarS22730 5 лет назад +1

    Please fix! why the healthBar.Setup(healthSystem) won't work on start method, it only works if it's in the update method

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      What do you mean by doesnt work? Do you have a NullReferenceException?

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

      @@CodeMonkeyUnity Assets\Scripts\GameHandler.cs(13,19): error CS0122: 'HealthBar.Setup(HealthSystem)' is inaccessible due to its protection level

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

      @@danielmurillo748 Sounds like you made Setup() private but are trying to access it from another class

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

    Just to say thank you, without you I wouldn't have made it. Thanks

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

      I'm glad the videos have helped you! Best of luck with your games!

  • @aka_bearz
    @aka_bearz 4 года назад +3

    Man please i really need your Help, my console didnt Show me the Health like you in 2:39 idk what im doing wrong :/ please it would be awesome if u can help me pls

    • @Stabs100
      @Stabs100 4 года назад

      same thing is happenning to me

    • @ThePilotWhoCantFly
      @ThePilotWhoCantFly 3 года назад

      im guessing you have given up already

    • @aka_bearz
      @aka_bearz 3 года назад

      No, ive learned a lot about how to programm in unity, save data, about how to controll the cinemachine and post processing, solving the problems and i want to keep using unity because i think is a great tool and if u have a problem maybe it will took days, weeks but at the end you will understeand how to do it.

    • @mkgames4539
      @mkgames4539 3 года назад

      @@aka_bearz im having the same issue :( please help

    • @aka_bearz
      @aka_bearz 3 года назад +1

      @@mkgames4539 So u cant see results in the console? Be sure u are attaching your Script to a GameObject

  • @Carvajal121
    @Carvajal121 5 лет назад +6

    very simple and effective code

  • @shaikhsaleemtraders9640
    @shaikhsaleemtraders9640 3 года назад +1

    U should type slow and explain code to the viewers so bigginers like us can also understand

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      What part couldn't you understand? Take you time and pause as much as you need, this is your learning journey, not a race

  • @muhamademam4328
    @muhamademam4328 5 лет назад +4

    Why you did't use UI instead of GameObject for the health bar ?
    is this better for performance ?
    Thank you for the tutorials and good job

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +3

      This health bar is mean to be placed on top of a Unit that exists in the game world so it makes sense to use a normal Game Object instead of the UI.
      If I made it as a UI bar I would have to do a world position to ui position calculation every single frame which if you have multiple bars at once could become costly.
      If you only have a single unit that you wish to display the health, like just the player, then it would make sense to have a single UI Health Bar.

    • @muhamademam4328
      @muhamademam4328 5 лет назад

      @@CodeMonkeyUnityThank you for this information
      can you please make a tutorial about profiling and how to track performance and optimization that would be very helpful

  • @ハロ-s9r
    @ハロ-s9r 3 года назад

    Thank you for making the game so easy to understand

  • @noxwareentertainment3169
    @noxwareentertainment3169 5 лет назад

    Code Monkey, this is RUclips channel, what everyone has been searching for all the time. If there is someone, who is not subscribed Code Monkey yet, I recommend! Here you can check some cool tips for coding, what everyone wants to do. Good job Code Monkey, continue on this way! 💪

  • @bsdrago
    @bsdrago 4 года назад +2

    Hey man, congrats for your videos!! I saw you use a lot of events. Can you do a video explaining how it works? Keep the good job!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Yeah I'd love to do a complete C# course one day and explain all the core concepts.

    • @bsdrago
      @bsdrago 4 года назад

      @@CodeMonkeyUnity Im not sure if who are in your channel really need a complete C# core course (IMHO). But some core concepts, from who come from WindowsForms programming , as a example, Its not quite clear how to use events (or the difference between events and UnityEvent, seens the same to me) in a game. I already watched a lot of your videos and this caracteristc (events) in your code is very strong and I liked. So, when you think about this choice in your code, you can do a video =)

  • @oreoicecream1829
    @oreoicecream1829 3 года назад

    Your videos really help alot of people 👍❤️🙏

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

    I have a question about this system and applying it to other objects (Enemies, etc.), but does there NEED to be a gamehandler for EVERY object? I feel like this point wasn't explained too well

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

      Nope, that's just for testing. You would simply do new HealthSystem(); in your Player/Enemy class to create a health system.
      By the way I have since remade this system and made it into a proper free asset unitycodemonkey.com/video.php?v=tf8NhUgORQg

  • @aseemudgirkar9087
    @aseemudgirkar9087 3 года назад

    I have the codeMonkey utilities installed and set up yet the buttons will not show up. What should I do?

  • @paulushcgcj
    @paulushcgcj 6 лет назад +2

    Pretty Cool. It would be nice if you make a random spawn tutorial

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +3

      What exactly do you mean by random spawn? In this video the spawning of the enemies is pretty basic, they spawn on playerPosition + randomDirection * random(50f, 100f);

  • @xexeons632
    @xexeons632 3 года назад +1

    The health doesnt show up, Nothings comes in my console beside code from my other scripts
    public class HealthSystem
    {
    public int health;
    public HealthSystem(int health)
    {
    this.health = health;
    }
    public int GetHealth()
    {
    return health;
    }
    }
    using UnityEngine;
    public class GameManager : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {
    HealthSystem healthSystem = new HealthSystem(100);
    Debug.Log("Health: " + healthSystem.GetHealth());
    }

  • @shahankit-clashofclans3796
    @shahankit-clashofclans3796 6 лет назад +3

    Hey dude,
    i love your RUclips video and i want to see more videos from your channel

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      Thanks!

    • @kantallive
      @kantallive 6 лет назад

      Once I've reached the certain point of knowledge of Unity and coding I will watch entire channel in way of searching for the answers which will eventually comes xD

  • @maxengl139
    @maxengl139 4 года назад

    How can I make the player die when health = 0
    1

  • @hasansyed5572
    @hasansyed5572 5 лет назад +1

    Hi, how do you get the health bar to follow your player? i know you dont make healthbar the child of player, but dont see where you copy position values.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      In the end I did make it a child of the player, just didn't record that part.
      That's the simple way to do but you can also keep it a global object and just make a script to follow a Transform on Update.

  • @youngveteranrica286
    @youngveteranrica286 3 года назад +1

    help!!! i followed all he steps but when i clicked on play this error poped up ( error CS0123: No overload for 'HealthSystem_OnHealthChanged' matches delegate 'EventHandler' )

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад +1

      What is the function signature for HealthSystem_OnHealthChanged?
      It needs to be (object, EventArgs)

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

    How could I make a health system but the health bar is a diagram of a plane and when it gets damaged to a certain extent it changes Color from green to yellow to red?

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

      You can use a Mask to get a health bar of any shape docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Mask.html
      Then change the image.color

  • @azkaakza8005
    @azkaakza8005 3 года назад

    the script I typed from the sample video could not be attached to the game object, for a reason the script don't inherit a native class that can manage a script

  • @christophfriedrich5092
    @christophfriedrich5092 3 года назад +1

    Why did you create an extra class only for the health? Why not put it into the healthbar script where you won't have any trouble instantiating a new object of class Health and then assign it to the healthbar script?
    Wouldn't it be better to have the code of a specific part at that specific part?

    • @klarnorbert
      @klarnorbert 3 года назад

      SOLID principle. One class should only do one thing. It's more scalable, for example, because you can use it for enemies, or other entities which doesn't need a healthbar. Reuseability.

  • @ujjawalk6780
    @ujjawalk6780 6 лет назад

    Yes sir please do somewhat slowly so that we could understand. This will surely help in your channel growing

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      What specific part of the video did you find hard to understand?

    • @ujjawalk6780
      @ujjawalk6780 6 лет назад

      Code Monkey I am a newcomer to the world of coding and game development. So I have many doubts more than my imagination . So I request you to do tutorial somewhat in a explanation manner

  • @ElijahQ06
    @ElijahQ06 5 лет назад +1

    Hello,around the time 8:30 I get a problem which is NullRefrenceException: Object reference not set to an instance of an object Health bar
    May someone please help

    • @gamesbygrigg7447
      @gamesbygrigg7447 5 лет назад

      did you forget to add the script to the health bar?

  • @BeKindPlox
    @BeKindPlox 6 лет назад +2

    Can you show how you got that blood effect on the ground?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +1

      Yeah I'm planning on making a video about that particle system sometime in the future, cheers!

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

    The healthbar doesn't work for me. I had to change x position from "5" to "0.5" in the bar and "-5" to "-0.5" on the spritrbar in order to get it to not shift away. Hope that helps you.

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

      What didn't work? The local size depends on the parent size, and the parent size will depend on how big you want it to be and the size of your camera

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

      When the x position is at "5", the barsprite shifts left when the scale is lowered. I don't know why changing it to "0.5" on the x position fixes the shifting and it works for me.

  • @josephc.t8651
    @josephc.t8651 3 года назад

    I really going to follow u 😀
    I was intrested in coding and stuff in unity but i tried brackey channel tutorial but the cod was not working and i stoped opening unity i will now try it again with ur tutorial 😎

  • @EMandMORE
    @EMandMORE 6 лет назад +2

    Great Channel, immediately subscribed! Please go on with 2D unity games, I would LOVE to see also Android game Apps. Thank you

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      Thanks!

    • @EMandMORE
      @EMandMORE 6 лет назад +1

      Code Monkey how many years of experience do you have with C# programming and Unity engine?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      I've been working with Unity and C# for 5 years.
      I started doing game development in Flash in 2008 then transitioned to Unity in 2013.

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

    Want it a better idea to declare the health variables as float in the first place?

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

      Depends on what values you want for your health, if you need decimal points yes use float, if you just need whole numbers use int

  • @MycoalD
    @MycoalD 3 года назад

    I created a PlayerCollision script that makes it sense whenever the player touches an item. When it does this, the player would take damage. How would I get the healthSystem (HealthSystem healthSystem = new HealthSystem(100);) into the PlayerCollison? Thanks

  • @lvlGhostlylvl
    @lvlGhostlylvl 4 года назад

    Anyone else have a problem with the healthbar being way off camera? It's working perfectly other then it doesnt follow the player. I've rewatched the video countless times, but I guess the part that shows how to lock the HP bar above its object isn't in the video.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Either constantly update the healthBar.position to match the player.position or make it a child of the player.

    • @lvlGhostlylvl
      @lvlGhostlylvl 4 года назад

      @@CodeMonkeyUnity Thanks! I subscribed to your channel by the way I can't wait to watch your other videos!

  • @johku433
    @johku433 5 лет назад +1

    Where i have to put HealthSystem script?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      Anywhere in your project files, its just a simple class.

    • @johku433
      @johku433 5 лет назад

      @@CodeMonkeyUnity Thank you

  • @YellowWhyHardGamerTV
    @YellowWhyHardGamerTV 5 лет назад +1

    If I want to change from the damage button to a monster, do damage instead. how i can do this. Thank you

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      The class doesnt care where the damage came from, you just need to call the damage function wherever you want to deal damage.
      So in that case wherever you are handling monster damage call the function.

    • @YellowWhyHardGamerTV
      @YellowWhyHardGamerTV 5 лет назад +2

      @@CodeMonkeyUnity How to call function. Do you have a sample?

  • @ansariscreativity2615
    @ansariscreativity2615 4 года назад +1

    What's the software u r using

  • @y.a5427
    @y.a5427 2 года назад

    How do I code a special move for an RPG character

  • @unityerda2752
    @unityerda2752 4 года назад +1

    My console says nothink

  • @pinoygaming75
    @pinoygaming75 5 лет назад +1

    Wow, AMAZING TUTORIAL.....WHAT COMPILER YOU ARE USING?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      It's being compiled by Unity using the normal compiler.

  • @mikadini88
    @mikadini88 5 лет назад +1

    For learn how to crete a game i must start with this video? Or i can take causal video and learn to it without move in order

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      The only videos that have a specific order are in Playlists.
      So check those out and for all the other videos you can pretty much just pick a topic you're interested in and watch it.

  • @rileyethier1626
    @rileyethier1626 4 года назад +1

    The Health System is great and functions perfectly. I'm a bit new to programming though and am curious. How can I modify the health system to account for multiple enemy and player types having different max healths?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      Each enemy or player has its own instance of a HealthSystem, so each of those can have different maximum values

  • @TheDew389
    @TheDew389 5 лет назад +1

    Pls tell me what is GameHandler.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      It's just the script used for testing the Health System, simple MonoBehaviour added to a gameObject.

    • @ilovedinosaurs5425
      @ilovedinosaurs5425 5 лет назад

      @@CodeMonkeyUnity thx i had an error now it works again xd

    • @TheDew389
      @TheDew389 5 лет назад

      Thx

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

    Assets\2DPlatformerCharacterController\Scripts\GameHandler.cs(2,7): error CS0246: The type or namespace name 'CodeMonkey' could not be found (are you missing a using directive or an assembly reference?)
    is there a solution?

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

      Where are you seeing that? The 2D platformer isn't used in this video.
      If you want a health system I've since polished this system in a newer video unitycodemonkey.com/video.php?v=tf8NhUgORQg

  • @cfam8193
    @cfam8193 4 года назад

    For some reason when I do the transform.Find to get the health percentage it doesn't work and I don't know why and there are no errors in the console.

  • @prettymplsgirl
    @prettymplsgirl 4 года назад

    Where are you putting Gamehandler and HealthSystem?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      GameHandler is just attached to a Game Object, nothing special about it. The HealthSystem doesn't extend MonoBehaviour so it's not attached ot anything.

  • @EmsiFreddi-zw7dl
    @EmsiFreddi-zw7dl Месяц назад

    Got a question about how did you architected your player.
    I've heard that its a good practice to make a player with scripts in a modular way, where you will have 1 script for example dedicated for the player movement and another script for example the health system. I've seen that in the proyect files you use all of that in the PlayerHandler, so my question is. What's your opinion on using this moduled version, is it just better to have 1 script in the player that manages everything or making a moduled version.
    And also if you want to upgrade for example a stat like max health or damage, how could this be done?
    Thanks 😀

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Месяц назад +1

      It really depends on the situation, depends on how complex is the game, how complex is the project you're making, etc. Sometimes I make the health a field on the player, other times I make it a separate component, both options can be valid.
      I made a modular character controller here ruclips.net/video/mJRc9kLxFSk/видео.html
      And I did a new version of this health system here ruclips.net/video/tf8NhUgORQg/видео.html

    • @EmsiFreddi-zw7dl
      @EmsiFreddi-zw7dl Месяц назад

      @@CodeMonkeyUnityokay thanks a lot! 😊

  • @michaelmyers1806
    @michaelmyers1806 5 лет назад +1

    I am having a problem attaching the health bar to an enemy. When I attach the script to an enemy the health bar Instantiates in the same spot it was originally created and is not attached to the enemy. Is there something that I am missing?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      The Health Bar should be instantiated as a Child of your Enemy game object so it follows along. I only noticed that after I stopped recording so that part isn't shown in the video.
      Just change the Instantiate code
      Transform healthBar = Instantiate(pfHealthBar, enemyTransform);
      Vector3 healthBarLocalPosition = new Vector3(0, 10);
      healthBar.localPosition = healthBarLocalPosition;

    • @michaelmyers1806
      @michaelmyers1806 5 лет назад

      @@CodeMonkeyUnity Thank you for this. It is much appreciated.

  • @joysanimationstudio2375
    @joysanimationstudio2375 4 года назад

    everything work properly until finish except button ui codemonkey didnt appear in the last time when it in the prefab. can you help me ?

  • @bsce100
    @bsce100 5 лет назад +1

    Thank you for posting this video, could you please tell me where I attach the two scripts to? Would HealthSystem be attached to the Player?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      HealthSystem is a simple class so you can create it wherever you want like inside your Player class.

  • @southkoreausasmaster8805
    @southkoreausasmaster8805 5 лет назад

    Thanks,very useful!

  • @hypnoticturtle9384
    @hypnoticturtle9384 5 лет назад +1

    I don’t understand how you moved the anchor point of the bar sprite, I’ve watched multiple tutorials of yours that explain that but it never works for me

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      You move the inner object to the right of the parent origin. Then when you scale the parent it will act like a pivot on the child.

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

    Im kinda stuck at 3:48. I can't get the buttons to show at all :(.
    But hey, great content and great tutorials!

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

      Those are made using my utilities, perhaps you have your UI set up in a different way, but you can use any buttons you want like the built-in Unity UI buttons, all it matters is how it interacts with the HealthSystem

  • @harrywood3698
    @harrywood3698 5 лет назад +1

    Im having some trouble with the health bar, when i test it, instead of scaling down on the X, it scales up on the Y, and its when printing the characters health, could you please help me?, it would be greatly appreciated.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +2

      Check how you're modifying the localScale and make sure you're changing localScale.x and leave localScale.y as it is or set it to 1.

  • @Endlessvoidsutidos
    @Endlessvoidsutidos 4 года назад

    cool vid sauce thanks for all the sweet sauce tips

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

    UI Buttom from Utilities does not work... I downloaded and added. Then, I used debug in the same was as on the video. The button does not appear.

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

      Do you see any errors in the console? What size is your camera? Pause the video, chances are the button was created but outside the camera. Or you're using a 3D Camera.

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

      @@CodeMonkeyUnity no errors in the console. I did some debugging, and the code is executing. Yes, i use a 3d camera. It does not work for 3D?

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

      @@CodeMonkeyUnity How can I fix it for 3d camera?

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

    You are just the best!!

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

    This is a great video, but how do I make it if health = 0 it turns my animator off?

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

      if (health == 0) animator.enabled = false;
      Or a better way, listen to the OnDied event and disable the animator

  • @johngrey5806
    @johngrey5806 5 лет назад

    In this video you made your own health bar from scratch, but I'm using one from the Energy Bar Toolkit. It has an Energy Bar script which reveals Value Current, Value Min, and Value Max in the Inspector. How do I feed these values from your HealthSystem into the Energy Bar script so that the custom Energy Bar displays the health correctly? Thank you for your response.

  • @mirapakulinek
    @mirapakulinek 3 года назад

    IT works on 3d game ?

  • @syeo19sy
    @syeo19sy 6 лет назад +1

    This video is quite good but i got a question to ask as i use your script. How do you change your maximum health. As like in game if you wear armor your maximum health will increase

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +1

      You would make another function to modify the healthMax that is set in the constructor.

  • @rafaelmodel
    @rafaelmodel 4 года назад +1

    Hi, great tutorial, I'm having problems with the sprites size. I tried in another computer and worked fine, but in my computer I'm having this problem. Tried reinstalling Unity, then the entire system, older versions of unity... nothing works. Any suggestions?

    • @claudio5012
      @claudio5012 3 года назад

      I have tried several resources from the "project files" on unitycodemonkey.com, but in no case the resource works when i try to use same texture sprite or material. I bought one of the udemy course and everything works ... so I think it is as intended.

  • @mu4fin582
    @mu4fin582 4 года назад

    my health bar is not apearing above the player and i dont know how to fix that :/

  • @felipeberthier973
    @felipeberthier973 4 года назад

    I was able to instantiate the pfHeathBar as a child of my Player but the Health Bar rotates with my Player, how can i fix this? Great Tutorial, best channel so far, i feel like i can create my entire game just from watching your videos! Thank you so much for the great content.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Make a script that resets the rotation on Update(); and add it to the bar.
      transform.eulerAngles = Vector3.zero;

    • @felipeberthier973
      @felipeberthier973 4 года назад

      @@CodeMonkeyUnity Oh, Thank You So Much!!

  • @ezgames7512
    @ezgames7512 5 лет назад

    Liked the video, but you seemed to go over some things to fast. I understand it is hard to cover everything, but your videos might be better if you explained why you are doing things more then just showing the steps.

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

    What's to stop a heal event for the player from healing enemies too with events broadcasting like that?

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

      Not sure what you mean, the event isn't static so the event only belongs to a single instance
      Also I made an updated version of this system here unitycodemonkey.com/video.php?v=tf8NhUgORQg

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

      @@CodeMonkeyUnity I'll check that out now, but I guess my question means if I put this same script on enemy prefabs, will it not conflict with the player?

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

      @@ImTheMrFoxman Each HealthSystem instance is separate. They will only share the healthsystem if you intentionally reuse the same object

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

      @@CodeMonkeyUnity ah! Okay, perfect. Thank you for the replies.

  • @androxz7
    @androxz7 5 лет назад

    Why did you choose to use a sprite as HB instead of a world space canvas attached to the player with a filled image?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      That would be a very needlessly complex answer to this problem, you would essentially create a new canvas for every single health bar you wanted to create. And the canvas is really meant for UI elements so if something is meant to live in world space then you should make it in world space.
      It would work but I wouldn't use that approach even if you just wanted one health bar.

  • @ujjawalk6780
    @ujjawalk6780 6 лет назад +1

    Sir it is terrain or a cube and if a terrain how you added these grass textures

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      The background is simply a SpriteRenderer with a grass texture. Cheers!

  • @hermanator5543
    @hermanator5543 5 лет назад

    ok it worked but I have a problem with my prefab because when I press play its really small and it isnt on the camera because its on a canvas and it doesnt stay with the player it just stays still

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      The HealthBar is built using the SpriteRenderer so it should be placed in the World and not in the Canvas.
      Is everything else small or just the bar? If it's everything then check your camera OrthographicSize.

  • @SilentKiller-7
    @SilentKiller-7 4 года назад +1

    Hi , your videos are great i am looking forward to use unity.
    Do you think my pc can handle unity?
    My specs are=
    intel pentium g3220
    6gb ram
    500g hd
    Intel hd graphics
    ( I also have a nvidia quadro fx 1800 but im not using it )
    +im total newbee in programming

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Sure probably, it's free so just download and try it out.

  • @no.sixtyseven8195
    @no.sixtyseven8195 2 года назад

    I would of loved to do some of the Debugging tools like the damage and heal buttons but im in VR. Any suggestions? Im kinda following without the debugging and its causeing me a bit of time cause when i have an issue it doesnt show immediately. Also the health bar is on a world space canvas so im having to adapt the code of course

  • @hungquang2957
    @hungquang2957 6 лет назад +1

    why did u remove the inheritance between HealthSystem and MonoBehavior

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +1

      To keep the code clean and as decoupled as possible. If it doesn't need MonoBehaviour there's no reason to add unnecessary dependencies.

  • @toddlerseducation9382
    @toddlerseducation9382 4 года назад

    someone can Help me how can I decrease the player healthbar because the player took damage there is part that i could'nt understand

  • @luismunoz9126
    @luismunoz9126 6 лет назад +1

    there is a posibility por us to get some of the assets from your videos?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      The assets are included in the project files for this video.

  • @programmingclashing
    @programmingclashing 6 лет назад +1

    How do i apply this to when it hits an enemy, it loses 10 hp?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      You need some way for the unit who is attacking to grab a reference to the Health System of the enemy taking damage. Then just call the damage function.

  • @carlosfer2201
    @carlosfer2201 4 года назад

    I don't understand how you used the console to check the code. If it's in another video, please let me know which.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      You mean the log messages? It's just Debug.Log();

    • @TheAmishUpload
      @TheAmishUpload 4 года назад

      @@CodeMonkeyUnity i cant find it either. following what you did, it does not show where to put the GameHandler script

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      @@TheAmishUpload The GameHandler is simply attached to a Game Object just like any Unity component.

  • @siscoye9454
    @siscoye9454 5 лет назад +1

    followed nicely BUT! Where is hell did Game handler come from, is it an empty object placed on the scene with the game handler script attached? there was no explaining this!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад

      Yes the GameHandler script is just attached to an empty game object so you can use the Start as an entry point to the code.

    • @siscoye9454
      @siscoye9454 5 лет назад

      Thank you mate , I might come across dumb, but it threw me right off, thanks for the tut

  • @alexg9188
    @alexg9188 3 года назад +1

    Hi! Nice video, thanks a lot. But could u please explain me why unity devs don’t like getters / setters. You method GetHealth() and private field could be just replaced with Health {get;}

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      I don't know about other Unity developers but for me I'm not a fan of Properties, they look like Variables but act like Functions, I'd rather keep my code as explicit as possible

  • @wernerdietrich7429
    @wernerdietrich7429 4 года назад

    How do I make the Healthbar move along with my Char?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад +1

      Either make it a child of the player or make a script to constantly update its position

    • @wernerdietrich7429
      @wernerdietrich7429 4 года назад

      ​@@CodeMonkeyUnity Wow that was fast Thank you! The idea to move it along the character was my thought as well, but how can I access the variables you defined in the start funktion?

  • @britrulog8234
    @britrulog8234 5 лет назад +1

    hello, hey, on 5:58 im having trouble to understand why this works. Im new to unity and Im not getting what is Bar for, I mean, its an object with just a "transform" so its basically a position, why does the scale of the Bar affects on the BarSprite?? And why the shift of barsprite to the right and bar to the left? Can someone please help, Im using this method but I wanna know how it works!!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 лет назад +1

      The Bar is just an empty GameObject that serves as the pivot for the inner BarSprite which is the GameObject that contains the actual sprite.
      So by shifting the BarSprite to the right you are making the Bar work as a pivot on the left.
      Then with the Bar working as a left pivot you can change the scale to easily modify the BarSprite size going from left to right.
      If you left the BarSprite on localPosition 0,0 then by changing the scale of the Bar it would scale the BarSprite from both sides.
      Hope that helps!

    • @britrulog8234
      @britrulog8234 5 лет назад

      @UCFK6NCbuCIVzA6Yj1G_ZqCg thanks!! I understand better now

  • @deadlockgamer420
    @deadlockgamer420 4 года назад

    Can we use mask and slider UI for the health system also will it be effecting the performance ?

  • @no.sixtyseven8195
    @no.sixtyseven8195 2 года назад

    Why Cant I call the Damage function or the heal function in a different script? I have a collider that is working but i want to add that it does damage but it wont let me or i dont know how??

    • @no.sixtyseven8195
      @no.sixtyseven8195 2 года назад

      public class CubeKiller : MonoBehaviour
      {
      private void OnTriggerEnter(Collider other)
      {
      if (other.gameObject.tag == "Destroy")
      Destroy(other.gameObject);

      //Need to damage the health system here!
      }
      }

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

      You need to do something like other.gameObject.GetComponent().Damage();

    • @no.sixtyseven8195
      @no.sixtyseven8195 2 года назад

      @@CodeMonkeyUnity how can i do that when the health system script cant be put on an object?

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

      @@no.sixtyseven8195 You create the HealthSystem on whatever unit/player script you have.
      If you want to use it as a component I made an updated version of this system here unitycodemonkey.com/video.php?v=tf8NhUgORQg

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

    I’m having a problem with setting the healthsystem = new HealthSystem(max health)… unity says you can’t create new through a mono behavior and should use add component or scriptable object it says in error console.. I try to add a variable gameobject to trygethealthsystem out of it and it’s just really hard to get it working.. I got it working earlier and even got fire to damage my character… then I tried adding scriptable objects for playerhealth and I screwed it all up 😅

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

      The HealthSystem in this video is a regular C# class, it does not extend MonoBehaviour
      By the way I have an updated version of this system here unitycodemonkey.com/video.php?v=tf8NhUgORQg

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

      @@CodeMonkeyUnity yes I have that healthSystem .. Sorry, I thought I was commenting on that video.. In the healthsystem component (I meant), it uses MonoBehaviour and has the healthSystem = new HealthSystem(100) and thats what's giving me a error. I'm going to try to reimport everything again and maybe I messed with something

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

      @@CodeMonkeyUnity I’m gunna let you know if I get it

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

      @@CodeMonkeyUnity it says HealthSystem is missing the class attribute ExtensionOfNativeClass

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

      @@CodeMonkeyUnity Nevermind I figured it out!!! I also implemented scriptable objects and combined the healthbar and healthsystem together so that I can drop it on anything I want to have health and a healthbar, along with the healthsystem component to just get the healthsystem for other scripts... I erased everything on healthsystem component and put it on to the regualr healthsystem. Listen ok... it wasn't working so i made it work LMAO

  • @FuzzyDPozzy
    @FuzzyDPozzy 6 лет назад +1

    also i try to create on my own and i get CMDebug not exist... Is it because of the Using CodeMonkey?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      Yes CMDebug is a helper class part of the CodeMonkey Utilities which you can download from the website.

    • @FuzzyDPozzy
      @FuzzyDPozzy 6 лет назад

      i see but what if codemonkey goes down in the future i will also lose the cmdebug right ?

    • @FuzzyDPozzy
      @FuzzyDPozzy 6 лет назад

      or if you download it it does not matter ?i mean if it needed to work required the codemonkey website

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад

      The package contains the source for the utilities, there's no network connection.

  • @zandra8830
    @zandra8830 6 лет назад +1

    I don't see where you explain how you add the health to the enemies...the enemies just have the health bar outta the blue. I want the player and enemies to use the same system.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 лет назад +1

      You instantiate the HealthSystem wherever you need it.
      So on your Enemy Class you would have a member variable and instantiate it with new HealthSystem(healthAmount);

  • @marjo.1700
    @marjo.1700 3 года назад

    Can you upload the code files that you wrote on this video in your website? I know it's an old video but I'm stuck almost in the end. Thanks!

  • @benasulin297
    @benasulin297 3 года назад

    How do i make it so that when the player connects with an object that has a tag, for example "bullet" they get damage dealt

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 года назад

      You can use the Physics system to listen to collisions ruclips.net/video/Bc9lmHjqLZc/видео.html

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

    It's giving me an error. It says "transform.localScale assign attempt for 'Bar' is not valid. Input localScale is { Infinity, 1.000000, 0.000000 }. UnityEngine.Transform:set_localScale (UnityEngine.Vector3)". Can you help?

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

      Are you dividing by 0? You cannot assign something to infinity scale

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

      @@CodeMonkeyUnity Yeah maybe. Can you tell me how to fix it?

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

      @@loldude8238 You have to look at how you're calculating the health value

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

      @@CodeMonkeyUnity Thanks, I rewached the video and tried it again. It works. Thank you

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

    this is confuseing can please show us from the start idk what did u add those to scripts to and where

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

      What start? The basics of Unity? unitycodemonkey.com/video.php?v=E6A4WvsDeLE

  • @alexaras5767
    @alexaras5767 4 года назад

    I'm very confused. How do you add that health bar to other objects such as enemies. And how do you trigger the damage from other enemies?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 года назад

      To deal damage you just call the function, from where you do that depends on what you're trying to do, there's a multitude of ways to do it.
      You can have a projectile with Physics and call Damage on collision, or maybe you want an instant shot and you call it based on a Raycast, or maybe it's based on a Animation System.