i keep getting the error nullreferenceexception and it also will not display the GUIs even though i have set the variables and the lifePercent variable seems to be functioning correctly. Any help on fixing the error and showing GUIs? (script worked perfect untill i added the section to draw the GUIs)
Health and GUI code-
var MaxHealth = 100;
var Health : int;
function Start ()
{
Health = MaxHealth;
onGUI();
}
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
RespawnMenuV2.playerIsDead = true;
Debug.Log("Player Died");
}
function RespawnStats ()
{
Health = MaxHealth;
}
var lifeRemainingBehindTexture : Texture;
var lifeRemainingTexture : Texture;
var lifePercent : float;
private var left : float;
private var top : float;
private var backgroundWidthLife : float;
private var lifeWidth : float;
private var height : float;
function onGUI()
{
lifePercent = Health / MaxHealth;
left = Screen.width / 2;
top = 8;
backgroundWidthLife = Screen.width / 4;
lifeWidth = lifePercent * backgroundWidthLife;
height = 12;
//players health GUI drawing
GUI.DrawTexture(Rect(left,top,backgroundWidthLife,height), lifeRemainingBehindTexture, ScaleMode.StretchToFill, true, 1.0);
GUI.DrawTexture(Rect(left,top,lifeWidth,height), lifeRemainingTexture, ScaleMode.StretchToFill, true, 1.0);
}