Hi fellow Uniters, anyone have any idea why I keep getting an "Array is out of index" errors on the following line:
GUI.DrawTexture(playerHealthRect, lifeBarTexture[i], ScaleMode.ScaleToFit, true, 0.0f);
I got this code from another post. Thanks for the help. The complete code is below:
// LifeBar.cs - script to handle player and enemy lifebar
public class LifeBar : MonoBehaviour
asked May 04 '12 at 07:33 AM
This is because lifeBarTexture is uninitialised and thus is empty.
On the line that causes the error you are looking in the lifeBarTexture array at the i'th index, but because it is empty that entry is blank.
To fix this look at the GameObject that contains this script in the Inspector. There (under the LifeBar script component) you will see a "Life Bar Texture" field. Add Texture components to this field until it has the same number of entries as the "Player Health" field (defaults to 10, but could also be set in the Inspector).