x


Help with NullReferenceException

var H00 : Texture2D;
var H10 : Texture2D;
var H20 : Texture2D;
var H30 : Texture2D;
var H40 : Texture2D;
var H50 : Texture2D;
var H60 : Texture2D;
var H70 : Texture2D;

var MAX_HEALTH = 70;
var HEALTH = 70;
function Update()
{
    var g_Health = GameObject.Find("g.Health");
    if(HEALTH > MAX_HEALTH){
    HEALTH = MAX_HEALTH;
    }
    if(HEALTH > 60){
    g_Health.guiTexture.texture = H70;
    }
    else if(HEALTH > 50){
    g_Health.guiTexture.texture = H60;
    }
    else if(HEALTH > 40){
    g_Health.guiTexture.texture = H50;
    }
    else if(HEALTH > 30){
    g_Health.guiTexture.texture = H40;
    }
    else if(HEALTH > 20){
    g_Health.guiTexture.texture = H30;
    }
    else if(HEALTH > 10){
    g_Health.guiTexture.texture = H20;
    }
    else if(HEALTH > 0){
    g_Health.guiTexture.texture = H10;
    }
    else if(HEALTH <= 0){
    g_Health.guiTexture.texture = H00;
       return;
    }
}

from this javascript I get this error NullReferenceException Health.Update () (at Assets/Scripts/Health.js:19) and I have no idea why PLEASE HELP

more ▼

asked Jan 15 '12 at 03:00 AM

lijrobert gravatar image

lijrobert
16 2 5 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

This can be caused be several things:

  • Maybe your Gameobject with the guitexture doesn't have the name "g.Health".
  • Maybe there are more than one objects with that name.
  • The GameObject with the name "g.Health" doesn't have a GUITexture component attached.
more ▼

answered Jan 15 '12 at 03:03 AM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

I continue to be amazed by my own stupidey, it was named Health not g.Health Slap Face

Jan 15 '12 at 03:19 AM lijrobert
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3746
x1961
x398
x36
x27

asked: Jan 15 '12 at 03:00 AM

Seen: 534 times

Last Updated: Jan 15 '12 at 03:19 AM