Need help with script (421122)

So I have a script that is saying that there are no errors, but its not doing what it is suppose to do. It attaches to a boss to make it have 10 (or whatever I put in) hit points. This is what I have so far:

var NextL6 : Transform; 
var BossHealth : int = 10; 
function Update () 
{ 
NextL6.renderer.enabled=false; 
if (BossHealth == 0) 
{ 
Destroy(gameObject); 
NextL6.renderer.enabled=true; 
} 
} 
function OnTriggerEnter(hit : Collider) 
{ 
if(hit.gameObject.tag == "wormProjectile") 
{ 
BossHealth--; //(or BossHealth -= 1, either would work fine); 
} 
}

everything seems perfect but it is dieing in one hit. so I need something that will do the same thing but actually work. The var NextL6 you can ignore. It is hiding the teleporter to the next level until the boss is killed. Any fixes thanks.

I don’t see any obvious problems with the code. Did you try adding debug output, like we were talking about in your other thread?

Do one of the objects have a rigid body attached to it?

All of the objects have rigid body’s (except for the next level thing)

Like I said what is a debug option… > im very new still

In this case it’s nothing fancy. One of the Unity classes is a ‘Debug’ class that offers a few simple services such as drawing lines and printing stuff to the console. One of the functions, Log(), simply prints a string of text to the console. (The console is a window that can be opened from the Window menu or by using a keyboard shortcut. Also, the last message logged to the console is typically displayed at the bottom of Unity’s main window.)

So, in your case, you might do something like this:

if(hit.gameObject.tag == "wormProjectile") 
{ 
    BossHealth--;
    Debug.Log("BossHealth decreased by 1");
}

Then run your program and test things out. If the boss disappears after only one hit, check the console and see how many times it says ‘BossHealth decreased by 1’. Does it say it only once? Or does it say it 10 time? This will give you some clue as to what’s going wrong. Then, you can start adding debug output elsewhere to further isolate the problem.

(I believe real debugging will be available in Unity 3, but if you’re using 2.x, using the Debug class is your best bet, I think.)

I am very confused, on what this is doing to help me. I open the window and just get millions of the same error? Not exactly sure what im suppose to be looking for. And it still dies in one hit?

Ok, let’s take one problem at a time. You say you’re getting ‘millions of the same error’. What is the error? Can you post the error here?

Ok so when I first start up the game I get this error:

Automatic import for ‘Assets/Music/techno-music-podcast-86.mp3’ was disabled because the asset importer crashed on it last time.
You can Reimport the asset or rename it in the file manager to force reimporting it.

Then when I start playing I get this error:

NullReferenceException: The prefab you want to instantiate is null.
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation)
WallColision.OnTriggerEnter (UnityEngine.Collider hit) (at Assets\AllScripts\WallColision.js:8)

Then also during play it repeats my worms health like hundreds of times:(This is not a an error though)

Lives: 3 Hits: 0
UnityEngine.Debug:Log(Object)
UnityEngine.MonoBehaviour:print(Object)
HCL5:Update() (at Assets\Levels\Level5\HCL5.js:12)

Also I tried a different method where I made two scripts for two things… one for the boss control to die, etc, and another for a health bar type of system.

So this code is attached to the boss:

static var die = false;

function LateUpdate () 

{
if(die)
{
Destroy(gameObject);
dead = true;
}
}
function OnTriggerEnter( hit : Collider )
{

if(hit.gameObject.tag == "wormProjectile")
{
BossHealthControl.HIT += 1;
Destroy(hit.gameObject);
}

}

And this code is attached to the health bar for the boss:

var health1 : Texture2D;  //one life left
var health2 : Texture2D;  //two life left
var health3 : Texture2D;  //three life left
var health4 : Texture2D;  //full health
static var LIVE = 4;
static var HIT = 0;

function Update () 
{
print("Boss Lives: "+LIVE+"Boss Hits: "+HIT); 
switch(LIVE)
{
case 4:
guiTexture.texture = health4;
break;
case 3:
guiTexture.texture = health3;
break;
case 2:
guiTexture.texture = health2;
break;
case 1:
guiTexture.texture = health1;
break;
case 0:
//Boss Dies, end of demo
BossDie.die = true;
Application.LoadLevel(6); //Demo end screen
break;
}
switch(HIT)
{
case 1:
//no action
break;
case 2:
//no action
break;
case 3:
//no action
break;
case 4:
LIVE -= 1;
break;
break;
}
}

Yet the boss still dies in one hit,even though it still has four lives and 4 hits per life?

I would start by trying to solve the prefab you want to instantiate is null error. I think if you double-click the error in the console it will take you to the line of code that’s trying to instantiate the prefab. So, your first task will be to determine why the prefab reference in question is null. (Is it a public variable that you haven’t assigned anything to?)