Health and mana bar:
This week I will be setting up a health and mana bar for my player, which is a really important feature for my game as it will determine whether the character should be alive or dead. Before I set up any functionality for losing health or mana, I will need to create the 'GUI' first, meaning the visual representation of the health and mana, as for starters the health has no need to go down at the moment anyway as there is nothing in my game to deal damage.
I would like the health and mana GUI to be at the top left screen, a popular location for the particular GUI. Unity allows for an easy way to control where you want you UI to be placed, as show here:
This GUI is my character portrait and resembles what character you are playing as, in this case no list of characters is set up and there is only one playable character anyway, but it's still a nice RPG UI element to have:
Here is what my UI looks like in my game so far but I may change it in the future, but for now I think it's a great size and position:
(At this point the UI does nothing, it's just sprite images on the canvas with no functionality)
Here is what it looks like in game:
Coding the health and mana functionality:
These 2 parts of the code selects what image is going to be changed, in this case the health and mana bar will have its 'fill' changed, meaning the less health or mana the character has the less the bars will be filled:
These just determine what the max health can be and also what the current health is:
This pretty much makes it so health doesn't go below zero and also so it doesn't go over 100:
This sets the max health and mana to 100:
Conclusion:
So today I created a semi-functioning health and mana bar, they should work but at the moment I don't have any other variables e.g enemies to hurt the character so the health bar actually goes down. Mainly today it was just about getting the GUI set up in the top left so there is a visual representation of my mana and health.
This week I will be setting up a health and mana bar for my player, which is a really important feature for my game as it will determine whether the character should be alive or dead. Before I set up any functionality for losing health or mana, I will need to create the 'GUI' first, meaning the visual representation of the health and mana, as for starters the health has no need to go down at the moment anyway as there is nothing in my game to deal damage.
I would like the health and mana GUI to be at the top left screen, a popular location for the particular GUI. Unity allows for an easy way to control where you want you UI to be placed, as show here:
This GUI is my character portrait and resembles what character you are playing as, in this case no list of characters is set up and there is only one playable character anyway, but it's still a nice RPG UI element to have:
Here is what my UI looks like in my game so far but I may change it in the future, but for now I think it's a great size and position:
(At this point the UI does nothing, it's just sprite images on the canvas with no functionality)
Here is what it looks like in game:
Coding the health and mana functionality:
These 2 parts of the code selects what image is going to be changed, in this case the health and mana bar will have its 'fill' changed, meaning the less health or mana the character has the less the bars will be filled:
These just determine what the max health can be and also what the current health is:
This pretty much makes it so health doesn't go below zero and also so it doesn't go over 100:
This sets the max health and mana to 100:
Conclusion:
So today I created a semi-functioning health and mana bar, they should work but at the moment I don't have any other variables e.g enemies to hurt the character so the health bar actually goes down. Mainly today it was just about getting the GUI set up in the top left so there is a visual representation of my mana and health.
Comments
Post a Comment