How to make a Health System | Unity Tutorial

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

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

  • @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

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

    It's been years. I'm *STILL coming back to these videos.

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

      It's always good to get a refresher on the basics!

  • @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...

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

    This is great. This is not for absolute beginners but when you are a little bit in unity then it is exactly the right speed for learning.
    ..and there is always the speed adjustment of youtube to slow the video down or speed it up. Also the pause function.

  • @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.

  • @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.

  • @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.

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

    Second I saw your ad I knew this is chanel I will like you just earned new subscriber gongrats

  • @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

  • @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!

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

    My game has Voxel, there is no need for a player health bar, Voxel’s skin becomes darker as health gets lower. Voxel can also camouflage, this is because Voxel can change colors because he is an amalgam of DNA, while glitch is his primary DNA, the DNA also comes from humans, Hydra (the freshwater polyp), Chameleon, Comb jelly, fish, and a tiny bit of Tardigrade.

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

    This is where everything began.

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

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

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

    Help me im trying to make it so when i pickup a apple i heal but the problem is that in the gamehandler script i need it to be in void update and not start. But then the heal dosent work so i have to go back to void start but then the pickup function dosent work. BTW i used the gamehandler gameobject with a sprite renderer for an apple because i couldnt access the heal from outside the object.

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

    Hey, so I have an issue with your video. I tried setting up the Bar exactly the same as you did, but mine doesn't remain inside the background, and everytime player, or enemy, gets hit the bar gets shorter until disappearing from human sight, leaving the background alone. How can I fix it? Thanks in advance.

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

      If you set it up exactly as in the video then the bar will stay inside the background as long as the localScale.x is between 0 and 1.
      If you set it to 2 it will have double the size of the background, if set to -1 it will scale to the left.
      Make sure you calculate the normalized value correctly and clamp it between 0 and 1.

  • @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

  • @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  Год назад

      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

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

    Another great tutorial. The typing sounds like a stampede.

  • @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

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

    my guy out here like VideoGameMonkey

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

    0:00 *a legend was born*

  • @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 =)

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

    If i do The Same it Shows Class and file Name dosnt match
    I cant use The script

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

      The file must be named the same as the class.
      So if the class is named HealthSystem the file must be named HealthSystem, cannot be different

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

    Damn 5 years ago, I remember occasionally getting an ad of your coding tutorials, and I visited your channel & subscribed because I am interested in video game development, it is sad that nowadays (probably based on region) it's just full of "GTA 5 On Mobile Phone Download For Free" adware scams

  • @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

  • @DannyArchive
    @DannyArchive 8 месяцев назад

    Was this your first ever video? Or how long have you been doing youtube?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 месяцев назад

      Yup this was the first video, almost 6 years now!

    • @DannyArchive
      @DannyArchive 8 месяцев назад

      ​@@CodeMonkeyUnity wow its really good for being your first video or did you have previus experience before starting this channel? Also just wanna say your a big inspiration on low cost living and being full time dev

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 месяцев назад

      heh it's interesting you say that because I think my presentation in this video is terrible, I was extremely uncomfortable speaking to a microphone so my voice clearly sounds very nervous/unconfident.
      Didn't have any previous experience, I just did a ton of research to learn how RUclips works, then I spend several weeks writing this video and preparing the demo, and then it took me about 5 recording tries before I got a version that was good enough to upload.

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

    very simple and effective code

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

    Thanks a lot! I'm begginer, so I don't know a lot of things and by your videos I can understand better C#. Earnead a new sub and like. Respect! :)

  • @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.

  • @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);

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

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

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

    What is the rationale behind not making the health system a monobehaviour? What are the benefits of initiating everything in a GameHandler? In this way, an attacker would have to access GameHandler to deal damage, right?

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

      The main benefit is access to the constructor, it depends if you like making your games primarily through code or through the editor.
      I've actually made an updated version of this system where I included both methods with and without MonoBehaviour unitycodemonkey.com/video.php?v=tf8NhUgORQg

  • @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.

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

    Thank you for making the game so easy to understand

  • @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.

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

    Very simple and understandable

  • @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

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

    I don't have a game handler though. Should this already be in place? If I already (somehow) got my player moving around the scene, would adding a gameHandler like you have throw something else off?

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

      GameHandler is just a name for a script, there's nothing special about that name. You can just create a new HealthSystem(); directly in whatever player script you already have.

  • @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

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

    Your videos really help alot of people 👍❤️🙏

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

    Thumbs Up, I wounder if you could remake this and Make it a bit noob friendly where you explain every single step as if we are very stupid lol. I would really appreciate it. You can even add in your thumbnail that its "for noobs", or even make 2 videos of every topic, one for those experts who just want to copy and paste the code since they are vets and one for noobs who need every little thing spelled out.
    I know its a hassle but I bet you that you will get more views for the noob friendly ones!!
    Anyway, even if you dont, I really like your videos! and I appreciate you.
    A good way to look at it would be; Imagine you have a 7 year old kid and you want your kid to be the best programmer in the world, so you start teaching your kid early but you have to explain to them every step so they dont get overwhelmed nor intimidated. And I must say I get very intimidated on your channel and feel like an importer, but you do have the best content out there so I have no choice but feel like an idiot and watch. I say this out of love, because I really believe this will grow your channel faster.
    Thanks again for all your hard work, and I know that your style has become more noob friendly, but IMO it has a long way to go.

  • @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! 💪

  • @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

  • @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

  • @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

  • @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! 😊

  • @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)

  • @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.

  • @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.

  • @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 😎

  • @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.

  • @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());
    }

  • @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.

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

    It won’t show in the console for me and everything is identical

  • @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.

  • @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.

  • @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.

  • @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?

  • @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!

  • @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.

  • @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.

  • @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.

  • @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?

  • @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

  • @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

  • @123sohra
    @123sohra 4 года назад

    Hey Codemonkey, is your GameHandler just an Empty Game Object?
    Thanks.

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

    Since we've subscribed our delegate to our EventHandler, is it good practice to Unsubscribe it on some occasions?
    When and how to do so?
    Correct me if i'm wrong thanks and cheers!

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

      If you destroy the UI element linked to the HealthSystem you need to unsubscribe before you destroy it. Otherwise you'll get a NullReferenceException when the HealthSystem tries to fire the event.
      If you destroy the HealthSystem you could unsubscribe but if the health system is destroyed the events wont ever be called again so not a huge issue if you leave it.

  • @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 ?

  • @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.

  • @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

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

    What's the software u r using

  • @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!!

  • @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.

  • @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!

  • @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.

  • @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?

  • @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

  • @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.

  • @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!

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

    For some reason my health bar only scale correctly but it only show full or empty, idk why.

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

      Sounds like you're making the mistake of dividing two ints so the result is only either 0 or 1 ruclips.net/video/0Ho3R7RBBiA/видео.html

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

      @@CodeMonkeyUnity Nop, I’m using floats and the scale change correctly but for some reason with 1 stay full but with any other quantity the bar change to empty, sorry I’m beginner

  • @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

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

    The health bar scaling thing doesn't seem to work for me? Does it just not work anymore?

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

      How does it not work? Make sure the pivot is placed correctly.

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

      @@CodeMonkeyUnity how do I move the pivot, I tried moving the red thing to the right and the bar to the left, but when I adjust the scale of the bar, it just moves it left and right

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

      @@mikaylag5237 You move the child to the right and then modify the parent

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

      @@CodeMonkeyUnity okay, so, for some reason, the thing that I tried last night and didn't work, worked now, idk what happened

  • @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

  • @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

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

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

  • @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

  • @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.

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

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

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

    Hey I am getting an error
    In the health bar script "healthSystem.OnHealthChanged += HealthSystem_OnHealthChanged;"line
    Error CS0123
    No overload for "HealthSystem_OnHealthChanged" matches deligate "EventHandler"
    Please help

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

      The signature on your method HealthSystem_OnHealthChanged must match (object, EventArgs)

  • @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.

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

    cannot download the files i create an account and it says my email is already in used when i click the forgot password it won't send an email or anything can you upload it somewhere else?

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

      Hmm odd, can you try again? Someone else reported a similar issue but it worked after some time.

    • @fernandoa.iriarte685
      @fernandoa.iriarte685 6 лет назад

      I have the same issue, already tried with 3 emails