I implemented the Health Bar solution found here: http://answers.unity3d.com/questions/4456 for health bars. The problem is, once I get 4 or 5 instances of the health bars on the screen the frames per second is down a good amount.
For a single bar it might be fine, but for a larger number it doesn't appear to be viable. Any recommendations?
Edit: Found a code problem which helped... but I still wonder if there is a quicker way to draw the bars.
Calling OnGUI from multiple objects might be the culprit. Try assembling a group of healthbars into an array and only having one handler object run OnGUI over those objects.
Something like this pair -
Create exactly one Healthbars object and any number of LivingThing objects.
LivingThing.js
var health : float;
var maxhealth : float;
function Start() {
Healthbars.AddBar( this );
}
Healthbars.js
static var healthbars : Array();
static var instance : Healthbars;
function Start() {
if ( instance ) throw ("Duplicate Healthbars instance: " + gameObject.name );
instance = this;
}
static function AddBar( lt : LivingThing ) {
healthbars.Add( lt );
}
function OnGUI() {
for ( var lt : LivingThing in healthbars ) {
// display code goes here
}
}