Yeah that's a Mask, you have one background that is visible normally and another one that is only visible when there's a mask. Then you just add a circle with a Mask to follow the mouse.
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues. UnityEngine.Transform:set_parent(Transform) HpVisual:CreateHeartImage(Vector2) (at Assets/Scripts/HpVisual.cs:74) HpVisual:SetHearthHealtSystem(HpSystem) (at Assets/Scripts/HpVisual.cs:47) HpVisual:Start() (at Assets/Scripts/HpVisual.cs:26) help?
Hi Code Monkey! After some work i actually managed to make your system with health upgrades available as well as only 1 fragment heart! I wanted to ask you permission to make a video about that, since i have seen lot's of comments from people which wanted to do that and didn't realise how to do it! Your videos are awesome, thanks for everything. If i don't get a response, which would bd quite normal since your channel is quite big and i can get lost between hundreds of comments, i will anyways do the video, since i didn't get a negative. But if you don't want me to do it, just contact me and it will be instadeleted, thanks! Of course, the description would have your video and channel!
Excellent tutorial! Could anyone tell me how to increase the number of hearts after the game has started? I’ve tried changing the code, but I can’t get it to work.
Hey, at 6:28ish when you write "return heartImage;" your code is okay but mine says "can't implicitly convert type 'HeartHealthImage' to 'UnityEngine.UI.Image' What did I do wrong?
Oh, I found the error. The name of the class was Image and not HeartImage. Hey man, your work is amazing. I'm really impressed. Thank you for everything. I'll make sure to donate as soon as possible. You're the boss.
Just an observation: At 8:15 you forgot to correct the line "HeartImage heartImage = new HeartImage(heartImageUI);" The correct is: "HeartImage heartImage = new HeartImage(this, heartImageUI);"
I might be 2 years late but maybe I'll help some people with this, it should work well but don't judge me if it's not perfect, i am not an expert. To Add a container you have to add this function to the heartsHealthSystem: public void AddHeartContainer() { Heart heart = new Heart(0); heartList.Add(heart); if (OnAddContainer != null) OnAddContainer(this, EventArgs.Empty); } then add a Event on top o named its like so: public event EventHandler OnAddContainer; then go to your heartsHealthVisual and add this to your Function where your set your HeartsHealthSystem: heartHealthSystem.OnAddContainer += HeartHealthSystem_OnAddContainer; and create a method for it i made it so (I have made it so that you heal fully when you add a heart): private void HeartHealthSystem_OnAddContainer(object sender, EventArgs e) { isHealing = true; AddNewHeart(); heartHealthSystem.Heal(2000); } now you have to put the rows and columns from the SetHeartsHealthSystem function to the top, so you can access it everywhere and add this function: private void AddNewHeart() { List heartList = heartHealthSystem.GetHeartList(); Vector2 heartAnchoredPosition = new Vector2(col * rowColSize, -row * rowColSize); CreateHeartImage(heartAnchoredPosition); col++; if (col >= colMax) { row++; col = 0; } } hope I havent forgotten anything
This is a lot of scripting and way over my head, but how can you add another heart container? I've tried updating the code in Start() for HeartsHealthVisual, but it does not update. What gives?
I was thinking if it would be possible to create a system that works in a similar way only using only full image and empty image and get the intermediate values by changing the fillAmount of the image_type of the image itself. I'm trying to create it this way, but I wonder if there is some reason why it can't be created this way?
Hey! There is an error - 8:13. Line 43, new HeartImage (heartImageUI). Unity says it needs also to add an element to the public class HeartImage like that: public HeartImage(Image heartImageUI) { this.heartImageUI = heartImageUI; } How did you fix that? The same way? p.s. Thank you for the tutorial.
i maybe a little to late but i had that problem but i put (this) OLD/ HeartImage heartImage = new HeartImage( heartImageUI); NEW/ HeartImage heartImage = new HeartImage(this, heartImageUI);
Hi, How can I use the Health system for my player to take damage when onTriggerEnter is called in my enemy script. I know I'm way late to this video, but I appreciate any help. Thanks
something I was dealing with as well. Ended up just using the navmesh system for now since I'm on a 3D. I will probably reevaluate later depending on time and performance.
Code works great, Have a question though. Is there a way to add invulnerability frames into this? I tried adding a coroutine to my enemies to disable the layer collision with the player for a few seconds but after it enables back I lose twice the amount of health if I stay inside the collider, is there a way around this? Thanks
Better to use a simple timer rather than modify the Physics System. Count down a simple float and when it's time to damage again do a raycast to test if hes still on top of a damageable object.
Codemonkey I love Your Health system But What are these Utilities Classes you are using is this a must have system for a good game . If it is then please make a video on this .
It's just a bunch of helper classes/functions that are useful in several scenarios. Like easily triggering an action after some time or every certain amount of time, or getting the mouse position or making a quick popup, etc You can download them from the website, it includes all the source code
I've downloaded the project files, and I see Health System in there, but I don't see the Spikes script or the HealthVisual script... what am I missing? I don't want to have to scan the video to copy the entire script if possible.
I have this error: "HeartsHealthSystem.Heart' does not contain a definition for 'GetFragmentAmount' and no accessible extension method 'GetFragmentAmount' accepting a first argument of type 'HeartsHealthSystem.Heart' could be found" This is the line: CreateHeartImage(heartAnchoredPosition).SetHeartFraments(heart.GetFragmentAmount()); Help Fast!
But how would you go about destroying and respawning your player on death? Probably a very simple solution, but I'm still learning. Any help would be appreciated
That depends a lot on how you set up your player. The simplest way would be to subscribe to the OnDamaged event and call Destroy(gameObject); on your Player. For respawn if your Player is set up as a Prefab you would just need to Instantiate() it.
For some reason my "return heartImage;" from 6:25 or so is underlined red saying that "Cannot implicitly convert type 'HeartsHealthVisual.HeartImage' to 'UnityEngine.UI.Image'" and I can't figure out why?
Hello. I am stuck on the .SetHeartFragments This is the error I get error CS1061: 'Image' does not contain a definition for 'SetHeartFragments' and no accessible extension method 'SetHeartFragments' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?) I can do the first part, CreateHeartImage(new Vector2(0,0)), but one I add the .SetHeartFragments. No dice. Any Ideas?
@@thatkarairamen Figured it out, the Function under void Start was private Image, but it needed to be changed to private HeartImage. Then delete the UI from return heatImageUI; Hope this helps private Image -> private HeartImage return heartImageUI -> return heartImage;
7:00 I get error CS0029: Cannot implicitly convert type 'HealthVisuals.HeartImage' to 'UnityEngine.UI.Image' not sure what I did wrong I've checked my code over many times and it seems to mirror yours.
I doubt you still have this issue, but for anyone else who gets stuck here. He changed a line but didn't mention it during the video. On line 27 he changed the type of the "CreateHeartImage" function from "Image" to "HeartImage". I hope this helps someone in the future.
Hey I'm having trouble with referencing, My OnHeal Heal and OnDamage Don't reference I set them to public but they don't appear in my HeartsHealthVisual script. Do you know what i could be doing wrong?
Why when I try to download the project to follow the tutorial, there's no sprite.. I can't follow it if I can't event build the character because the sprites are missing. Help please I wish to do your tutorials! You are awesome!
Which sprite can't you find? The only missing sprite is the background since I didn't make it and can't distribute it, you can find plenty of free background sprites in the asset store.
I covered SAving and Loading here ruclips.net/video/6uMFEM-napE/видео.html But if you just want to save between scenes then you can just store the data in static fields
@Code Monkey Wow, thanks for the fast answer but i am quite new to unity and c#, so could you please explain me how i can safe my current healthsystem into a static field and how to load it? That would be awesome 😀
@@CodeMonkeyUnity On my enemy class I added HeartsHealthSystem heartsHealthSystem = new HeartsHealthSystem(3); I guess I just do not know where to go from there
@@rexstayer-suprick2877 Now you just need to figure out how you're going to show the visual for each enemy and expose functions to cause damage to that health system instance.
@@CodeMonkeyUnity i did that but im getting this ERROR """"An object reference is required for the non-static field, method, or property 'Player.Damage'(int)"""" This is spike script [SerializeField] private int damageAmount; private void OnTriggerEnter2D(Collider2D collider) { Player player = collider.GetComponent(); if (player != null) { Player.Damage(damageAmount); } } } And this is player script public void Damage(int damageAmount) { HeartsHealthVisual.heartsHealthSystemStatic.Damage(damageAmount); } } PLEASE HELP
That's normal. Keep in mind that the length of the video is NOT how long it took me to learn this, or even record the video. A 20 minute tutorial takes me several hours to make, not to mention my 25 years of experience.
That's a tough one because its heavily dependent on what animation system you choose. The code part is a simple as having an enum for the WeaponType and swapping that, the animations are where it gets tricky.
hello from french. thank you for this video with systeme of heart of zelda but...for me, very hard to interstand the code from the 15 minute, j lost...j will come back next year or in 2025 :p so, j find other systeme, very simply but the style is little different, no transparency for exemple but, it's work, but, for new heart, j change manuelly the canvas... other problem : even if I do all the code, there are problems to create other hearts ... according to the comments. also my english is bad ... so i'm a little discouraged with this code TT maybe, if i have time i will come back (and j m not terminator ^^) but, think ^^
Randomly watched this as I was trying to figure out something, and poof it was here. Unfortunately I don't think it will help my scenario as I first thought.
This one came out great! Love the tiny animation on filling up the Hearts.
What elements from Zelda or other Adventure-RPGs would you like to see?
Pls tell how to do double-sprites like at 0:12 ruclips.net/video/dae5KKQSqC0/видео.html
@@kontroman sprite masking?
@@cristiano4826 i rly dont know, even sprite masking :D but want to know
Yeah that's a Mask, you have one background that is visible normally and another one that is only visible when there's a mask. Then you just add a circle with a Mask to follow the mouse.
i want to see when we push a button the player do an attack animation and stop the animation when it's finish
Thanks i got it
Yes i am so happy
After applying this into my game
Thank YOU very much for sharing this
more like Code GOAT. seriously, super awesome tutorial!
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent(Transform)
HpVisual:CreateHeartImage(Vector2) (at Assets/Scripts/HpVisual.cs:74)
HpVisual:SetHearthHealtSystem(HpSystem) (at Assets/Scripts/HpVisual.cs:47)
HpVisual:Start() (at Assets/Scripts/HpVisual.cs:26)
help?
This was really helpful! Thanks a lot!
Hi Code Monkey!
After some work i actually managed to make your system with health upgrades available as well as only 1 fragment heart!
I wanted to ask you permission to make a video about that, since i have seen lot's of comments from people which wanted to do that and didn't realise how to do it!
Your videos are awesome, thanks for everything.
If i don't get a response, which would bd quite normal since your channel is quite big and i can get lost between hundreds of comments, i will anyways do the video, since i didn't get a negative. But if you don't want me to do it, just contact me and it will be instadeleted, thanks!
Of course, the description would have your video and channel!
Sure, go for it!
where is the video?
I'm very new to game dev, Great tutorial.
How can I make a heart container that gives you a new heart when you collect it?
Omg that typing speed :P
Excellent tutorial! Could anyone tell me how to increase the number of hearts after the game has started? I’ve tried changing the code, but I can’t get it to work.
Hey, at 6:28ish when you write "return heartImage;" your code is okay but mine says "can't implicitly convert type 'HeartHealthImage' to 'UnityEngine.UI.Image'
What did I do wrong?
Oh, I found the error. The name of the class was Image and not HeartImage.
Hey man, your work is amazing. I'm really impressed. Thank you for everything. I'll make sure to donate as soon as possible. You're the boss.
Just an observation:
At 8:15 you forgot to correct the line "HeartImage heartImage = new HeartImage(heartImageUI);"
The correct is: "HeartImage heartImage = new HeartImage(this, heartImageUI);"
@@brunoverasferreira6263 Dude I'm so glad you wrote all of these comments. They saved my frustrations immensely.
Yes i have the same issue. it doesnot convert
@@brunoverasferreira6263 Thank you for your comments!! was very much stuck!
I might be 2 years late but maybe I'll help some people with this, it should work well but don't judge me if it's not perfect, i am not an expert.
To Add a container you have to add this function to the heartsHealthSystem:
public void AddHeartContainer()
{
Heart heart = new Heart(0);
heartList.Add(heart);
if (OnAddContainer != null) OnAddContainer(this, EventArgs.Empty);
}
then add a Event on top o named its like so:
public event EventHandler OnAddContainer;
then go to your heartsHealthVisual and add this to your Function where your set your HeartsHealthSystem:
heartHealthSystem.OnAddContainer += HeartHealthSystem_OnAddContainer;
and create a method for it i made it so (I have made it so that you heal fully when you add a heart):
private void HeartHealthSystem_OnAddContainer(object sender, EventArgs e)
{
isHealing = true;
AddNewHeart();
heartHealthSystem.Heal(2000);
}
now you have to put the rows and columns from the SetHeartsHealthSystem function to the top, so you can access it everywhere and add this function:
private void AddNewHeart()
{
List heartList = heartHealthSystem.GetHeartList();
Vector2 heartAnchoredPosition = new Vector2(col * rowColSize, -row * rowColSize);
CreateHeartImage(heartAnchoredPosition);
col++;
if (col >= colMax)
{
row++;
col = 0;
}
}
hope I havent forgotten anything
This is a lot of scripting and way over my head, but how can you add another heart container? I've tried updating the code in Start() for HeartsHealthVisual, but it does not update. What gives?
how to make it so you can add another heart when you pickup a heart container
I was thinking if it would be possible to create a system that works in a similar way only using only full image and empty image and get the intermediate values by changing the fillAmount of the image_type of the image itself. I'm trying to create it this way, but I wonder if there is some reason why it can't be created this way?
Hey! There is an error - 8:13.
Line 43, new HeartImage (heartImageUI). Unity says it needs also to add an element to the public class HeartImage
like that:
public HeartImage(Image heartImageUI)
{
this.heartImageUI = heartImageUI;
}
How did you fix that? The same way?
p.s. Thank you for the tutorial.
i maybe a little to late but i had that problem but i put (this)
OLD/ HeartImage heartImage = new HeartImage( heartImageUI);
NEW/ HeartImage heartImage = new HeartImage(this, heartImageUI);
You have saved my game. Thank you!
Hi, How can I use the Health system for my player to take damage when onTriggerEnter is called in my enemy script. I know I'm way late to this video, but I appreciate any help.
Thanks
can you please make a tutorial or tell me how i can make a heart container that give me a new heart?
Just add a new Heart to the List
@@CodeMonkeyUnity I have tried everything that I thought would work but it just does not work
@@CodeMonkeyUnity please can you give me the code what i need to put in my heart container script here?
First of all, congratulations, very good videos. I searched, but have not yet found any related to pathfinding :/
Yeah that's a pretty complex topic so I haven't managed to cover it yet.
something I was dealing with as well. Ended up just using the navmesh system for now since I'm on a 3D. I will probably reevaluate later depending on time and performance.
Thx men u are the best
how to make a heart start with a 3 heart, when the character find a new heart container the heart increase to 4 heart
How would I go about creating different hearts, say when it gets lower it changes to a broken heart?
Code works great, Have a question though. Is there a way to add invulnerability frames into this? I tried adding a coroutine to my enemies to disable the layer collision with the player for a few seconds but after it enables back I lose twice the amount of health if I stay inside the collider, is there a way around this? Thanks
Better to use a simple timer rather than modify the Physics System. Count down a simple float and when it's time to damage again do a raycast to test if hes still on top of a damageable object.
why isn't my heart showing up at the canvas when i press play? thx for your help!
Pause the editor and look in the hierarchy, is the object being instantiated?
Codemonkey I love Your Health system But What are these Utilities Classes you are using is this a must have system for a good game . If it is then please make a video on this .
It's just a bunch of helper classes/functions that are useful in several scenarios. Like easily triggering an action after some time or every certain amount of time, or getting the mouse position or making a quick popup, etc
You can download them from the website, it includes all the source code
@@CodeMonkeyUnityok thanks CM. Is This a good practice to make my own helper class and use them in my real good game project ?
Can you paste the code something dont work
I've downloaded the project files, and I see Health System in there, but I don't see the Spikes script or the HealthVisual script... what am I missing?
I don't want to have to scan the video to copy the entire script if possible.
Love all your work, can you please make a video about 2D pathfinding ?
I've love to but it's a very complex topic so not sure when.
I have this error: "HeartsHealthSystem.Heart' does not contain a definition for 'GetFragmentAmount' and no accessible extension method 'GetFragmentAmount' accepting a first argument of type 'HeartsHealthSystem.Heart' could be found"
This is the line: CreateHeartImage(heartAnchoredPosition).SetHeartFraments(heart.GetFragmentAmount());
Help Fast!
Seems you forgot to implement that function in the Heart class
How do i fix this? I have the same problem. I don't know how to implement that function in the Heart class@@CodeMonkeyUnity
But how would you go about destroying and respawning your player on death? Probably a very simple solution, but I'm still learning. Any help would be appreciated
That depends a lot on how you set up your player. The simplest way would be to subscribe to the OnDamaged event and call Destroy(gameObject); on your Player.
For respawn if your Player is set up as a Prefab you would just need to Instantiate() it.
#1
Hi bro plz create a server discord ✌
Yeah planning to very soon!
For some reason my "return heartImage;" from 6:25 or so is underlined red saying that "Cannot implicitly convert type 'HeartsHealthVisual.HeartImage' to 'UnityEngine.UI.Image'" and I can't figure out why?
HeartImage is the class name for a single heart instance and heartImageUI is the Image reference.
Alrighty, thanks dude
Hello.
I am stuck on the .SetHeartFragments This is the error I get
error CS1061: 'Image' does not contain a definition for 'SetHeartFragments' and no accessible extension method 'SetHeartFragments' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?)
I can do the first part, CreateHeartImage(new Vector2(0,0)), but one I add the .SetHeartFragments. No dice. Any Ideas?
That function is on HeartImage, not on UnityEngine.UI.Image
@@CodeMonkeyUnity I apologize, how do I fix that or what is needed to get it to work? I am sure I followed along. But I can not get it to work.
@@nickmalialis6 Did you ever fix it, because I'm having the exact same issue and their comment doesn't explain much
@@thatkarairamen Figured it out, the Function under void Start was private Image, but it needed to be changed to private HeartImage. Then delete the UI from
return heatImageUI;
Hope this helps
private Image -> private HeartImage
return heartImageUI -> return heartImage;
@@obelustorms you da best
7:00 I get error CS0029: Cannot implicitly convert type 'HealthVisuals.HeartImage' to 'UnityEngine.UI.Image' not sure what I did wrong I've checked my code over many times and it seems to mirror yours.
I doubt you still have this issue, but for anyone else who gets stuck here. He changed a line but didn't mention it during the video. On line 27 he changed the type of the "CreateHeartImage" function from "Image" to "HeartImage". I hope this helps someone in the future.
@@tgvoice5543 It sure did. Thx :)
Hey I'm having trouble with referencing, My OnHeal Heal and OnDamage Don't reference I set them to public but they don't appear in my HeartsHealthVisual script. Do you know what i could be doing wrong?
Are you accessing an instance of your class rather than the class name directly?
All they need to be is public in order to be used by other classes
@@CodeMonkeyUnity Thanks! I was indeed accessing the instance but its fixed now
P.S. Nice tutorial its helping me alot!
Why when I try to download the project to follow the tutorial, there's no sprite.. I can't follow it if I can't event build the character because the sprites are missing. Help please I wish to do your tutorials! You are awesome!
Which sprite can't you find? The only missing sprite is the background since I didn't make it and can't distribute it, you can find plenty of free background sprites in the asset store.
@@CodeMonkeyUnity and the player sprites? Where can I find yours? Or their are not distributed??
Thanks for reply!
They're all there in the package.
The character is at: _/Stuff/Textures/UnitSpritesheets/SwordTwoHandedBack.png
A Bit Late , but how to safe and load the healthsystem into another scene? Nice Tutorial btw, appreciate it
I covered SAving and Loading here ruclips.net/video/6uMFEM-napE/видео.html
But if you just want to save between scenes then you can just store the data in static fields
@Code Monkey
Wow, thanks for the fast answer but i am quite new to unity and c#, so could you please explain me how i can safe my current healthsystem into a static field and how to load it? That would be awesome 😀
How can I just import one game utilities and not each one of every game? Example this one and just open this not the others.
What do you mean? If you download the project files they only contain the files for this Heart Health System project.
How would I go about using this for enemies also
The HealthSystem is just a simple class, it can live anywhere. So on your enemy class just add a field for it and instantiate it.
@@CodeMonkeyUnity On my enemy class I added HeartsHealthSystem heartsHealthSystem = new HeartsHealthSystem(3);
I guess I just do not know where to go from there
@@rexstayer-suprick2877 Now you just need to figure out how you're going to show the visual for each enemy and expose functions to cause damage to that health system instance.
how to destroy Player when the heart health become empty?
Bro the Nested class doesnot work
Make a video similar to this but with only 2 fragments, I mean 1 heart full and one empty
watch this vid
ruclips.net/video/3uyolYVsiWc/видео.html
I can't download the Package.
Why not?
when i was making this i got those error lines underneath all my code so it didn't work :(
What errors?
@@CodeMonkeyUnity me error
CreateHeartImage(new Vector2(0,0)) error-> SetHeartFraments(1);
@@omargameover116 What error? If it's a NullReferenceException use Debug.Log to find out what is null ruclips.net/video/5irv30-bTJw/видео.html
How can i do spike without knockback?
The Knockback is a function that is called on the OnTriggerEnter2D(); function so just remove that and it won't be knocked back.
@@CodeMonkeyUnity i did that but im getting this ERROR """"An object reference is required for the non-static field, method, or property 'Player.Damage'(int)""""
This is spike script
[SerializeField] private int damageAmount;
private void OnTriggerEnter2D(Collider2D collider) {
Player player = collider.GetComponent();
if (player != null) {
Player.Damage(damageAmount);
}
}
}
And this is player script
public void Damage(int damageAmount) {
HeartsHealthVisual.heartsHealthSystemStatic.Damage(damageAmount);
}
}
PLEASE HELP
@@johku433 You need to do player.Damage(); not Player.Damage();
You're accessing the function in the player instance not in the Class itself.
Simple Ai Tracking with enemy facing player plz 2d?
This is awesome but extremely hard to follow along with. I had to literally pause it every few seconds to even keep up and see what you were typing.
That's normal. Keep in mind that the length of the video is NOT how long it took me to learn this, or even record the video.
A 20 minute tutorial takes me several hours to make, not to mention my 25 years of experience.
Can You Make How To Switch Weapons? im Having Truoble making xd
That's a tough one because its heavily dependent on what animation system you choose.
The code part is a simple as having an enum for the WeaponType and swapping that, the animations are where it gets tricky.
hello from french.
thank you for this video with systeme of heart of zelda but...for me, very hard to interstand the code
from the 15 minute, j lost...j will come back next year or in 2025 :p
so, j find other systeme, very simply but the style is little different, no transparency for exemple but, it's work, but, for new heart, j change manuelly the canvas...
other problem :
even if I do all the code, there are problems to create other hearts ... according to the comments.
also my english is bad ... so i'm a little discouraged with this code TT
maybe, if i have time i will come back (and j m not terminator ^^)
but, think ^^
Why do you use c# light mode? XD
Because dark mode burns my eyes. I've been using light for 20 years.
Randomly watched this as I was trying to figure out something, and poof it was here. Unfortunately I don't think it will help my scenario as I first thought.
😎
please rpg battle systems n.n