Hi all,
I was recently faced with the problem of how to dynamically fill non-rectangular status bars in the HUD for my game. I wanted to use Unity GUI but wasn’t able to find anything I could filch, ummm, that is reuse, from the forums or the Wiki. A number of other approaches were detailed, but I really wanted Unity GUI. So I set out to do it myself and, much to my amazement, seem to have been somewhat successful. 
As a result I have a C# script to share that I hope others will find useful as well. This script is used to implement a dynamically textured status bar, such as a health/energy/mana bar. It supports irregularly shaped bars within reasonable limits. As long as the fill area of the bar can be sensibly emptied and filled in a linear fashion (i.e. left-to-right, bottom-to-top, etc.), it can be implemented using a DynaBar. Usage of the script is documented in the script itself.
I’m still working on optimizing the script for performance. Suggestions for improvements are welcome.
Below is a screenshot of some sample bars I whipped up and also a unitypackage that contains a simple usage of the script. I recommend you create a new Unity project and then import the DynaBar package.
Cheers!
Mal
235467–8435–$dynabar_152.unitypackage (1.09 MB)

Interesting. Can you explain how exactly does this work?
Sure. Central to its operation are four textures. The first three you create and the fourth is dynamically created:
-
the bar: the “outline” of the bar that you want to fill. It has an interior region that will be filled and emptied in response to events in your game.
-
the fill: this texture is the fully filled interior region of the bar. Easily made, for example, in Photoshop by using the magic wand to select the interior region of the bar texture and then applying color.
-
the clear: this texture is the fully empty interior region of the bar. When the bar is “empty” it can still be textured if you want. If you want it to be clear, just have this texture be all transparent pixels.
-
dynamic bar: this texture is created at Start time. It’s going to be updated dynamically to contain the appropriate mix of the fill and the clear texture.
Each time you call the updateBar method of the script you pass it the percent filled the bar should be. The method looks at the current percent fill of the bar and decides whether the bar is emptying or filling on this call. If filling, it grabs the appropriate strip of pixels from the fill texture and uses SetPixels to put them in the dynamic texture. Likewise from the clear texture if the bar is emptying.
The script itself is well documented and contains additional details if you’re curious. Also, the package contains the bars shown in the screenshot so you can see how they’re put together.
Cheers,
Mal