How to make a Heart Health System like Legend of Zelda (Unity Tutorial)

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

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

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

    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?

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

      Pls tell how to do double-sprites like at 0:12 ruclips.net/video/dae5KKQSqC0/видео.html

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

      @@kontroman sprite masking?

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

      @@cristiano4826 i rly dont know, even sprite masking :D but want to know

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

      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.

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

      i want to see when we push a button the player do an attack animation and stop the animation when it's finish

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

    Thanks i got it
    Yes i am so happy
    After applying this into my game
    Thank YOU very much for sharing this

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

    more like Code GOAT. seriously, super awesome tutorial!

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

    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?

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

    This was really helpful! Thanks a lot!

  • @paraxodondev
    @paraxodondev 3 года назад +6

    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!

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

    I'm very new to game dev, Great tutorial.

  • @TheS1L3NT
    @TheS1L3NT 3 года назад +3

    How can I make a heart container that gives you a new heart when you collect it?

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

    Omg that typing speed :P

  • @diogobonilhabrandon5528
    @diogobonilhabrandon5528 3 года назад +3

    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.

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

    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?

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

      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.

    • @brunoverasferreira6263
      @brunoverasferreira6263 5 лет назад +15

      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);"

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

      @@brunoverasferreira6263 Dude I'm so glad you wrote all of these comments. They saved my frustrations immensely.

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

      Yes i have the same issue. it doesnot convert

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

      @@brunoverasferreira6263 Thank you for your comments!! was very much stuck!

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

    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

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

    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?

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

    how to make it so you can add another heart when you pickup a heart container

  • @matrixroby6584
    @matrixroby6584 3 месяца назад

    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?

  • @milyamusina
    @milyamusina 4 года назад +5

    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.

    • @oracleoftheavatar1883
      @oracleoftheavatar1883 4 года назад +5

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

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

    You have saved my game. Thank you!

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

    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

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

    can you please make a tutorial or tell me how i can make a heart container that give me a new heart?

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

      Just add a new Heart to the List

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

      @@CodeMonkeyUnity I have tried everything that I thought would work but it just does not work

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

      ​@@CodeMonkeyUnity please can you give me the code what i need to put in my heart container script here?

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

    First of all, congratulations, very good videos. I searched, but have not yet found any related to pathfinding :/

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

      Yeah that's a pretty complex topic so I haven't managed to cover it yet.

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

      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.

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

    Thx men u are the best

  • @mohamadjazman9239
    @mohamadjazman9239 5 лет назад +7

    how to make a heart start with a 3 heart, when the character find a new heart container the heart increase to 4 heart

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

    How would I go about creating different hearts, say when it gets lower it changes to a broken heart?

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

    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

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

      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.

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

    why isn't my heart showing up at the canvas when i press play? thx for your help!

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

      Pause the editor and look in the hierarchy, is the object being instantiated?

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

    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 .

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

      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

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

      @@CodeMonkeyUnityok thanks CM. Is This a good practice to make my own helper class and use them in my real good game project ?

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

    Can you paste the code something dont work

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

    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.

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

    Love all your work, can you please make a video about 2D pathfinding ?

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

      I've love to but it's a very complex topic so not sure when.

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

    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!

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

      Seems you forgot to implement that function in the Heart class

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

      How do i fix this? I have the same problem. I don't know how to implement that function in the Heart class@@CodeMonkeyUnity

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

    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

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

      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.

  • @revanstar5743
    @revanstar5743 5 лет назад +13

    #1
    Hi bro plz create a server discord ✌

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

    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?

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

      HeartImage is the class name for a single heart instance and heartImageUI is the Image reference.

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

      Alrighty, thanks dude

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

    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?

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

      That function is on HeartImage, not on UnityEngine.UI.Image

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

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

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

      @@nickmalialis6 Did you ever fix it, because I'm having the exact same issue and their comment doesn't explain much

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

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

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

      @@obelustorms you da best

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

    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.

    • @tgvoice5543
      @tgvoice5543 3 года назад +3

      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.

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

      @@tgvoice5543 It sure did. Thx :)

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

    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?

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

      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

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

      @@CodeMonkeyUnity Thanks! I was indeed accessing the instance but its fixed now
      P.S. Nice tutorial its helping me alot!

  • @94Kansas
    @94Kansas 5 лет назад

    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!

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

      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.

    • @94Kansas
      @94Kansas 5 лет назад

      @@CodeMonkeyUnity and the player sprites? Where can I find yours? Or their are not distributed??
      Thanks for reply!

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

      They're all there in the package.
      The character is at: _/Stuff/Textures/UnitSpritesheets/SwordTwoHandedBack.png

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

    A Bit Late , but how to safe and load the healthsystem into another scene? Nice Tutorial btw, appreciate it

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

      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

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

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

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

    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.

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

      What do you mean? If you download the project files they only contain the files for this Heart Health System project.

  • @rexstayer-suprick2877
    @rexstayer-suprick2877 5 лет назад

    How would I go about using this for enemies also

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

      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.

    • @rexstayer-suprick2877
      @rexstayer-suprick2877 5 лет назад

      @@CodeMonkeyUnity On my enemy class I added HeartsHealthSystem heartsHealthSystem = new HeartsHealthSystem(3);
      I guess I just do not know where to go from there

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

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

  • @Jon-vg7pz
    @Jon-vg7pz 4 года назад

    how to destroy Player when the heart health become empty?

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

    Bro the Nested class doesnot work

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

    Make a video similar to this but with only 2 fragments, I mean 1 heart full and one empty

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

      watch this vid
      ruclips.net/video/3uyolYVsiWc/видео.html

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

    I can't download the Package.

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

    when i was making this i got those error lines underneath all my code so it didn't work :(

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

      What errors?

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

      @@CodeMonkeyUnity me error
      CreateHeartImage(new Vector2(0,0)) error-> SetHeartFraments(1);

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

      @@omargameover116 What error? If it's a NullReferenceException use Debug.Log to find out what is null ruclips.net/video/5irv30-bTJw/видео.html

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

    How can i do spike without knockback?

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

      The Knockback is a function that is called on the OnTriggerEnter2D(); function so just remove that and it won't be knocked back.

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

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

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

      @@johku433 You need to do player.Damage(); not Player.Damage();
      You're accessing the function in the player instance not in the Class itself.

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

    Simple Ai Tracking with enemy facing player plz 2d?

  • @celinedrules
    @celinedrules 5 месяцев назад

    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.

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

      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.

  • @jansamaran.7979
    @jansamaran.7979 5 лет назад

    Can You Make How To Switch Weapons? im Having Truoble making xd

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

      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.

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

    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 ^^

  • @MeTube-sg1tx
    @MeTube-sg1tx 5 лет назад

    Why do you use c# light mode? XD

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

      Because dark mode burns my eyes. I've been using light for 20 years.

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

    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.

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

    😎

  • @8978martin
    @8978martin 5 лет назад

    please rpg battle systems n.n