Sprint 5 Blog
Overview
For this sprint, I was responsible for the UI implementation of the game scene. This included player unit health bars, player stat hover, and enemy stat hover. This included collaboration with other programmers and referencing other existing scripts made by them. This feature will be expanded upon in the upcoming sprint.
Health Bar UI
I then created a health bar script that needed the parameters of the max health and current health of the unit with the script attached. Then, I added the function in the game unit script and inserted the stats variable with the respective values. This way, each unit is given their own health values depending on the type of unit they are made as in the level editor.
Stat Display
For the stat display, I had to create a basic canvas that could show each of the unique stats a player or enemy unit has. For this, I had a similar approach as the health bar. I would create a script that would need all the individual stats from the unit as the parameter. This included a variety of value types including ints, floats, strings, and an enum.
Here is what the script looks like. There are two main functions in this script: UpdateUnitStats and ResetUnitStats. The parameters are listed in the UpdateUnitStats function. They include all the stat unit types needed to be displayed as described earlier. Below is a shorter version but essentially the same functionality for the enemy units.
Unit Hover Stats
For the unit hover, I had to seek reference from other programmers code. We came up with the idea that I could utilize a function in their code in a similar way. For the player to click on a unit, the input manager checks to see if the grid coordinate is occupied by a unit. With this knowledge I had the script do a similar action, but this time it checked if the mouse was hovering over the unit's grid position to display its unique stats. This did come with some trial and error in the beginning though.
The video above shows the first iteration with the hover feature. There were a few bugs including the hover not working over units and only one specific unit's stats were shown. The hover worked in terms of it getting the stats data from the game unit script but it needed two improvements. 1) Having the hover work when the mouse was on top of the unit and 2) making the hover show the stats of the specific unit it's hovering.
Here is the updated code that accomplished both of these requirements. The Update() function is where the corrections were made and took inspiration from the input manager existing code. This is using a raycast and works for both player and enemy units. Below shows the outcome of the fixes.
Comments
Post a Comment