Collecting items doesn't reset when loading a new level?

As stated above I am having some issues with loading a level from collecting 3 items, here are the exact details:

First level - you collect 3 items and they display a HUD inventory as you collect them.
Once you collect three the game changes to the next level - at this time - nothing resets, the hud is blank and you can no longer see your items being collected - everything else works / item collisions etc.

Here’s my code:

ObjectCollect - on the gameobject / HUD

static var collect : int = 0;

var collect0tex : Texture2D;
var collect1tex : Texture2D;
var collect2tex : Texture2D;
var collect3tex : Texture2D;


var NameOfTargetLevel : String;

function NextLevel(){

	//var collect : int = 0;
	

	
	Application.LoadLevel(NameOfTargetLevel);


	
}


	

function Update () {
if(collect ==1) {
	guiTexture.texture = collect1tex;
	guiTexture.enabled = true;
	}
	else if(collect == 2){
		guiTexture.texture = collect2tex;
		}
		else if(collect == 3){
		guiTexture.texture = collect3tex;
		
		NextLevel();
		
		}
		else {
		guiTexture.texture = collect0tex;	
			}

}

this tells the game to display a hud and every time the character hits a trigger object with the ‘pickup’ script applied - the hud image will change / and on 3 will change to the target level.

Here is the pickup script:

//attach to object to pickup and collect points; set point value in hierarchy.

var points : int;

function Update () {
}

function OnTriggerEnter (col : Collider) {
var playerStatus : PlayerStatus = col.GetComponent(PlayerStatus);
playerStatus.AddPoints(points);



//Prints message in console (for debugging, not for game play):

//print ("Points added =  " +points);

//function OnTriggerEnter(){

    
    
        
    //TextHints.message = "Audio has been triggered.";
    //TextHints.textOn = true;


ObjectCollect.collect++;

    Destroy(gameObject);
}

Thanks for taking a gander at this if at all :slight_smile: (sorry for the long post I wanted to be as specific as possible. Also I’m not a programmer so this sort of thing is tough for me to tackle off the bat)

You need to remove the static keyword before collect. Static fields won’t change when you load a new level due to the fact that they are associated with the class itself, not an instance.

I just want to say thank you Peter - you are a life saver!! Sorry for the silly questions concerning code - I’m more familiar with the visual development of games.