Public Variable Help!

In my game, I’m trying to make a wave spawner, so that when every enemy dies it will start a new wave. Right now, either the death line or the variable itself is broken. Here’s my monster death system:

var Health : float = 100;
var MaxHealth : float = 100;
var Manager : GameObject;

function OnTriggerEnter(hit : Collider){
if (hit.CompareTag("EditorOnly")){
Health = Health - 1;
}
}

function Update(){
if (Health <= 0){
Manager.livingCreatures = Manager.livingCreatures - 1;
Destroy(gameObject);
}
}

And my Wave script (I modified it from an existing one):

    var totalCreatures : int = 2; 
    static var livingCreatures : int = 0;
    var waitToWave : float = 10;
    var waveTime : float;
    var yourCreature : Transform;
    var CurrentWave : float = 1;
    var text : GUIText;
    
    function Update() {
     text.text = CurrentWave.ToString();
        if (livingCreatures == 0) {
     
            if (waitToWave <= waveTime) {
                waveTime = 0;
                livesCreatures = totalCreatures;
     
                for (var i = 0; i > totalCreatures; i++) 
                    Instantiate (yourCreature, Vector3(0,0,0), Quaternion.identity);
                    totalCreatures = totalCreatures * 2;
     				CurrentWave = CurrentWave + 1;
            }else {
                waveTime += Time.DeltaTime;
            }
        }
    }

It’s getting an error that says “NullReferenceEception: Object reference not set to an instance of an object.”
Please help!

I noticed a possible error that may be the cause of your code issue.

In your monster code at line 14:

Manager.livingCreatures = Manager.livingCreatures - 1;

It should be:

Manager.GetComponent('WaveSpawn').livingCreatures = Manager.GetComponent('WaveSpawn').livingCreatures - 1;

And probably changing in your WaveSpawn script:

static var livingCreatures : int = 0;

for:

public var livingCreatures : int = 0;

That’s it. The rest of the code looks good. At least from here hehe.
Try adding some Debug.Logs every here and there so you know exactly how far your code ran before crashing.

Good luck.

Solved it! If anyone would like to see the final code, I can show you. Thank you all for helping me, and I know where to go next time I have a problem.