My Fifth Game Design Blog Post – Creating Damage Feedback on Players Health.

In this post, I will write about my damage feedback on player’s health. One of my tasks this week was to create a damage feedback on the player’s health. I tried to make the health bar blink but it didn’t fully work out so instead I made it to change to red color for a second and go back to white again.

blog5pic.png

(Health bar normally.)

blog5pic2.png

(Health bar after taking damage.)

Whenever the enemy deals damage to the player the health bar of the player becomes red for one second and then comes back to be the default color. First I fetched the image of the health in code and made a method that is so called Coroutine.  Coroutine is a timer, for example you have something that you want to activate for some amount of time and then deactivate it. In this case, it was changing the color of the health bar to red for a second which was done in a function, but I will come to that later.

You basically fetch the image and get image’s sprite renderer which is in the sprite itself, then you make a function that does something with the image, which in my case was to make the sprite renderer to change color from white to red for one second.

The time you can write in the coroutine itself or make a specific variable that hold’s the amount of time you want, so that you can use it whenever you want.

To use coroutine with the function the function must be specific one which in this case is IEnumerator. This one means basically “to count off or name one by one” and is often used with the coroutine. In the IEnumerator is where I change the color and change it back again in one second.

One issue I had with this was that all my images in UI started to change the color with the health. I could not find why so I asked my game designer who helped me to find another solution on the internet which he found. To make it work I had to specify much more precisely which Image from UI I wanted to fetch so that the code doesn’t fetch all of the images.

Leave a comment