https://streamable.com/tf84c6
Please tell me how to correctly implement the life bar in the UI, namely:
1. movement of the red bar to show the fullness of the heart.
2. Digital value display of life in the form of numbers.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
How are you recording "life"? As a Global variable?
Variable values can be displayed in Label elements via text tokens - see this tutorial.
For your red bar, custom scripting would be necessary - since you'd be looking to control the size of the Image's RectTransform based on the variable's value.
First though, you'll need to set its RectTransform's Pivot X value to 0, so that changing its Scale X property is all you need - no need to also affect the position.
What is the maximum "life" value, and what is the maximum "Scale X" value on the RectTransform (i.e. the scale X when fully red)?
Made according to the lesson looks good.
Did as you said.
https://streamable.com/xxlsbv
Regarding the maximum value, there is a difficult answer. Since the parameter life in the game is not an unambiguous parameter. This means that the player will have 100 life units and when the value is 0 he will die. But in the game I plan to implement the "Equipment" system, which means that if the player put on a T-shirt, then +2 units were added to the life parameter, if he put on a bulletproof vest, then +25 was added. And at the same time, the text value can reach 125 units, since it is a text and a number, but with a strip, the value here should remain no more than 100 (a red-foamed heart), since a red strip will appear in RectTranform. At the moment, I have 0 = 0 life from the length of the strip, and 100 units of life in RectTranform for X is 1.5.
https://streamable.com/xxlsbv
Can you please tell me how to implement this mechanism?
Create a separate variable named MaxLife to represent the maximum health the player can have - with a default value of 100.
Then attach this script to your life icon:
It works, but how do they organize the logic so that damage is done?
Or was life added from getting food?
A variable's value can be updated with the Variable: Set Action.