RTS Interlude #4: Improving the healthbars (Unity/C#)

Let’s digress for a while and leverage the power of shaders in our RTS game!

Mina Pêcheux
CodeX
Published in
12 min readFeb 18, 2022

--

⬅️ Tutorial #49: Optimisation tips & tricks| TOC | Tutorial #50: Implementing a technology tree 1/3 ➡️

📕 Get the ebook and bonus material on Gumroad!
🚀 Find the code of this tutorial series on my Github!

In previous episodes of the series, we talked a bit about how to create healthbars for our units. In particular, we had some logic to create a UI element and “snap it” above the head of the unit.

However, this technique is pretty flawed and not very efficient because:

  • the healthbars can quickly get strange offsets
  • we have to manually reposition them on the screen whenever either the camera or the unit moves, plus when the camera zooms
  • we are deleting and re-creating objects (the UI healthbars) each time we select or deselect our units

All these are bad and power-consuming… but there is a solution to improve all of this! So, today, let’s do a retake on our healthbars and see how we can use shaders to display them efficiently, robustly and easily :)

Using a simple quad to have the…

--

--

Mina Pêcheux
CodeX
Writer for

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)