🌐 Have you found the videos Helpful and Valuable? ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
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
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
@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.
@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 !
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
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
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.
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!
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.
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!
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.
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...
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.
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
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.
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.
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?
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.
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.
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.
@@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
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.
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.
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.
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.
@@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
@@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.
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
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
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
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.
@@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 =)
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
@@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
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.
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.
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.
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);
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?
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
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.
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.
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
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?
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.
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?
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.
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! 💪
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
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?
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
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 😀
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
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' )
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
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
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 😎
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
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()); }
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?
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.
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.
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?
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;
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
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.
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.
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.
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.
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
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!
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!
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.
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
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.
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.
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.
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!!
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!
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.
@@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
@@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
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;}
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
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?
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
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
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.
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
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
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.
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?
🌐 Have you found the videos Helpful and Valuable?
❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
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
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
@Brooks Aries Instablaster ;)
@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.
@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 !
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
What specific part of the video did you find hard to understand?
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
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.
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!
Debug.Log is used to display some information in the console and in this case it displays the health
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.
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!
Thanks :)
Getting a code monkey ad on code monkey's video
Code monkey: Stonks
thats like they are paying and getting it at the same time
I got an ad about your video on another video xd
Hope you liked what you saw!
sure do!
Lol
It's been years. I'm *STILL coming back to these videos.
It's always good to get a refresher on the basics!
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.
Can you help me?
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...
Glad you liked it!
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.
Thanks!
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
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!
Glad you like the videos!
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.
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.
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?
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.
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.
More videos coming soon! Thanks!
Im trying to make a game during my spring break. This vid helped me out a lot. Thanks bro I appreciate it.
That's awesome! Best of luck!
Second I saw your ad I knew this is chanel I will like you just earned new subscriber gongrats
Glad you like what you see!
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
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.
@@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
Just to say thank you, without you I wouldn't have made it. Thanks
I'm glad the videos have helped you! Best of luck with your games!
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.
This is where everything began.
It's been a long journey! Thanks for being here!
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.
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.
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.
Stay away if you’re absolute beginner, you will learn nothing but how fast this guy can type
You can pause the video at any time if you want to follow along. Where did you get lost?
@@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
@@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.
Please fix! why the healthBar.Setup(healthSystem) won't work on start method, it only works if it's in the update method
What do you mean by doesnt work? Do you have a NullReferenceException?
@@CodeMonkeyUnity Assets\Scripts\GameHandler.cs(13,19): error CS0122: 'HealthBar.Setup(HealthSystem)' is inaccessible due to its protection level
@@danielmurillo748 Sounds like you made Setup() private but are trying to access it from another class
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
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
Another great tutorial. The typing sounds like a stampede.
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
same thing is happenning to me
im guessing you have given up already
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.
@@aka_bearz im having the same issue :( please help
@@mkgames4539 So u cant see results in the console? Be sure u are attaching your Script to a GameObject
my guy out here like VideoGameMonkey
0:00 *a legend was born*
Over 3 years ago! Time flies!
@@CodeMonkeyUnity haha :p
@@CodeMonkeyUnity hello!
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!
Yeah I'd love to do a complete C# course one day and explain all the core concepts.
@@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 =)
If i do The Same it Shows Class and file Name dosnt match
I cant use The script
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
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
U should type slow and explain code to the viewers so bigginers like us can also understand
What part couldn't you understand? Take you time and pause as much as you need, this is your learning journey, not a race
Was this your first ever video? Or how long have you been doing youtube?
Yup this was the first video, almost 6 years now!
@@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
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.
very simple and effective code
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! :)
Glad to hear it!
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.
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.
Pretty Cool. It would be nice if you make a random spawn tutorial
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);
I have the codeMonkey utilities installed and set up yet the buttons will not show up. What should I do?
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?
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
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.
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
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.
Thank you for making the game so easy to understand
Wow, AMAZING TUTORIAL.....WHAT COMPILER YOU ARE USING?
It's being compiled by Unity using the normal compiler.
Very simple and understandable
Hey dude,
i love your RUclips video and i want to see more videos from your channel
Thanks!
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
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?
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.
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?
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
Your videos really help alot of people 👍❤️🙏
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.
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! 💪
Yes sir please do somewhat slowly so that we could understand. This will surely help in your channel growing
What specific part of the video did you find hard to understand?
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
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?
Each enemy or player has its own instance of a HealthSystem, so each of those can have different maximum values
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
Make sure you extend MonoBehaviour
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 😀
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
@@CodeMonkeyUnityokay thanks a lot! 😊
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' )
What is the function signature for HealthSystem_OnHealthChanged?
It needs to be (object, EventArgs)
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
You would make another function to modify the healthMax that is set in the constructor.
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
Sure probably, it's free so just download and try it out.
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 😎
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
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.
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());
}
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?
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.
It won’t show in the console for me and everything is identical
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?
HealthSystem is a simple class so you can create it wherever you want like inside your Player class.
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.
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.
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?
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;
@@CodeMonkeyUnity Thank you for this. It is much appreciated.
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
did you forget to add the script to the health bar?
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.
Either constantly update the healthBar.position to match the player.position or make it a child of the player.
@@CodeMonkeyUnity Thanks! I subscribed to your channel by the way I can't wait to watch your other videos!
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.
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
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.
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.
If I want to change from the damage button to a monster, do damage instead. how i can do this. Thank you
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.
@@CodeMonkeyUnity How to call function. Do you have a sample?
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
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!
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.
Thank you mate , I might come across dumb, but it threw me right off, thanks for the tut
Hey Codemonkey, is your GameHandler just an Empty Game Object?
Thanks.
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!
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.
everything work properly until finish except button ui codemonkey didnt appear in the last time when it in the prefab. can you help me ?
Great Channel, immediately subscribed! Please go on with 2D unity games, I would LOVE to see also Android game Apps. Thank you
Thanks!
Code Monkey how many years of experience do you have with C# programming and Unity engine?
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.
Im kinda stuck at 3:48. I can't get the buttons to show at all :(.
But hey, great content and great tutorials!
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
What's the software u r using
I'm using Unity and Visual Studio
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.
Make a script that resets the rotation on Update(); and add it to the bar.
transform.eulerAngles = Vector3.zero;
@@CodeMonkeyUnity Oh, Thank You So Much!!
why did u remove the inheritance between HealthSystem and MonoBehavior
To keep the code clean and as decoupled as possible. If it doesn't need MonoBehaviour there's no reason to add unnecessary dependencies.
Can you show how you got that blood effect on the ground?
Yeah I'm planning on making a video about that particle system sometime in the future, cheers!
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?
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.
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.
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.
@@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?
@@CodeMonkeyUnity How can I fix it for 3d camera?
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!!
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!
@UCFK6NCbuCIVzA6Yj1G_ZqCg thanks!! I understand better now
I don't understand how you used the console to check the code. If it's in another video, please let me know which.
You mean the log messages? It's just Debug.Log();
@@CodeMonkeyUnity i cant find it either. following what you did, it does not show where to put the GameHandler script
@@TheAmishUpload The GameHandler is simply attached to a Game Object just like any Unity component.
Why did you choose to use a sprite as HB instead of a world space canvas attached to the player with a filled image?
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.
Sir it is terrain or a cube and if a terrain how you added these grass textures
The background is simply a SpriteRenderer with a grass texture. Cheers!
For some reason my health bar only scale correctly but it only show full or empty, idk why.
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
@@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
Want it a better idea to declare the health variables as float in the first place?
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
The health bar scaling thing doesn't seem to work for me? Does it just not work anymore?
How does it not work? Make sure the pivot is placed correctly.
@@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
@@mikaylag5237 You move the child to the right and then modify the parent
@@CodeMonkeyUnity okay, so, for some reason, the thing that I tried last night and didn't work, worked now, idk what happened
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;}
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
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?
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
Can we use mask and slider UI for the health system also will it be effecting the performance ?
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
Where are you putting Gamehandler and HealthSystem?
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.
How can I make the player die when health = 0
1
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
The signature on your method HealthSystem_OnHealthChanged must match (object, EventArgs)
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
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.
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?
Hmm odd, can you try again? Someone else reported a similar issue but it worked after some time.
I have the same issue, already tried with 3 emails