Tower Health/Shield wiget
The tower Health/Shield wiget was implemented as a purely cosmetic purpose was meant to show the player the health of current units/towers easily and quickly without them having to select each tower or unit individually. It is a common mechanic that is found in many real-time strategy games.
upon the construction of a tower widget values are set straight away this goes off the of them begin play advance straight away we cast to the Tower health widget so we can access its many different variables this is done by getting the widget reference than using a node get use of widget object and this is the object cash to. If the cast returns is truewe then get the tower shield bar and Tower health bar and set them on the Tower so they can be referred to later easily. We then use a node set percentage and use the Tower health bar widgets and what we do is get that Tower health and then divided by the Tower health templates which both the same thing. The way this mass work is for example if the Tower health is 300 and we divided by 300 because the Tower health template is always the same as the Tower health is equal to 1 and then we set this percentage. But if the current health is to drop to say to 250 but the Tower health templates does not change and is still set to 300 this then equals to 0.833 which shortens the widget and create the effect it looks like the tower is losing health.
The trick is now when ever the tower health is changed it most updates the tower health bar widgets to keep the widget in sync with the current health so it can be shown visibly in the game.
This also has to be updated for the shield also so whenever the shield is taking damage or gaining health the tower shield bar widget must always be updated.
No comments:
Post a Comment