2D modular health system in Unity part 3

Daniel Kirwan
3 min readNov 15, 2021

Objective: Adjust the canvas on the player so that it is set to world space

In the two previous articles about the health system I setup the canvas prefab that contains my health system incorrectly. I noticed this when I tried to implement my turrets spawning into the game that the health bars were moving in a funny way, when they shouldn’t have moved at all. It took some time but I found a fix for it.

  1. In the canvas set the Render mode to “world space”, this will immediately move the health bar and you probably won’t be able to see it.

2. Make a prefab of your camera

3. Now you will need to have a camera added to the Event camera, drag in the camera prefab to the slot

4. Go into the prefab of the canvas object and you will need to do some scaling to the canvas and the healthImage

When you make the changes in the prefab you should see the changes take effect inside the game widow. When you’re happy with the changes you can come out of the canvas prefab.

Now, to the issue that was happening with the healthImage acting jittery when in play mode, this was because I was moving the healthImage to the parent position on every frame. This was causing the issue with the run time instantiated game objects.

To fix this I removed the method that I was calling for this:

And that was it for fixing my canvas health system for my little space game.

If you found this helpful, don’t forget to clap and follow for more articles on game development in Unity.

--

--