Getting NullReferenceException? info inside

I made a GameObject array to keep track of the current enemies for easy referencing, however I cannot get it to work right. It seems like everything is in order, and I can compile and play, but I get the NullReferenceException error when I play.

I am trying to create a script for platforms that the characters can pass through the bottom of.

The three errors I get are

NullReferenceException: Object
reference not set to an instance of an
object EnemySpawn.Start () (at
Assets/Custom
Assets/Scripts/Enemy/EnemySpawn.js:18)

NullReferenceException: Object
reference not set to an instance of an
object Passable Platform.Update () (at
Assets/Custom
Assets/Scripts/Stage/Passable
Platform.js:18)

NullReferenceException: Object
reference not set to an instance of an
object EnemySpawn.Start () (at
Assets/Custom
Assets/Scripts/Enemy/EnemySpawn.js:18)

And the Scripts are

------------------EnemySpawn.js--------------------

var spawn : Transform;
var spawnAtStart : boolean = false;
var self : GameObject;
var spawnedBool : boolean = false;
var myClone : GameObject;
var myCloneHealthScript : EnemyHealth;
var cloneBool : boolean = true;
var myCloneFollowScript : EnemyFollow;
var player : GameObject;
var StatisticsScript : Statistics;

function Start(){
	
	player = GameObject.FindWithTag("Player");
	StatisticsScript = player.GetComponent(Statistics);
	
	for (var i = 0; i <= StatisticsScript.enemyCount.Length; i++)
	{

    	if(StatisticsScript.enemyCount != GameObject) {

            StatisticsScript.enemyCount *= gameObject;*
  •  return;*
    
  • }*

  • }*

}

function Update () {

  • if(spawnAtStart == true){*
  •  spawnAtStart = false;*
    
  •  spawnedBool = true;*
    
  •  Spawn();*
    
  •  }else{*
    
  •  	if(spawnedBool == false){*
    
  •  		spawnedBool = true;			*
    
  •  		Spawn();						*
    
  •  	}*
    
  •  }*
    

}

function Spawn() {

  • spawnedBool = true;*

  • myClone = Instantiate(self, spawn.position, Quaternion.identity);*

  • myClone.name = “Clone”;*

  • myCloneHealthScript = myClone.GetComponent(EnemyHealth);*

  • myCloneHealthScript.cloneCheck = cloneBool;*

  • myCloneFollowScript = myClone.GetComponent(EnemyFollow);*

  • myCloneFollowScript.cloneCheck = cloneBool;*
    }
    --------------------------Passable Platform.js-------------------------------
    var StatisticsScript : Statistics;

//***********************************************************************************************
function Update () {

  • player = GameObject.FindWithTag(“Player”);*
  • StatisticsScript = player.GetComponent(Statistics);*

_ /* if the player is made up of more than one collider, you’d_
need to iterate over the colliders and use playerBounds.Encapsulate()*/

for(var i = 0; i <= StatisticsScript.enemyCount.Length; i++)
{

_ enemyBounds = StatisticsScript.enemyCount*.collider.bounds;_
_ enemyCheck(enemyBounds, StatisticsScript.enemyCount);*_

}

playerBounds = player.collider.bounds;
* playerCheck();*

}

//***********************************************************************************************
function playerCheck(){

* //check bottom of player to see if it is above the platform*
if(playerBounds.min.y >= collider.bounds.max.y)
{
* Debug.Log(“player is above platform”);*
//make the platform solid
Physics.IgnoreLayerCollision(8, 10, false);

}else{
* Debug.Log(“player is below platform”);*
//turn off platform collision
Physics.IgnoreLayerCollision(8, 10, true);

}

}

//***********************************************************************************************
function enemyCheck(enemyBounds : Bounds, enemy : GameObject){

* if(enemyBounds.min.y >= collider.bounds.max.y)*
* {*

* Physics.IgnoreCollision(collider, enemy.collider, false);*

* }else{*

* Physics.IgnoreCollision(collider, enemy.collider,true);*

* }*

}
----------The relevant script from Statistics.js----------
static var enemyCount : GameObject[];

It’s tough to say without seeing more, but are you instantiating your array, and if so is it happening before it’s being used by these scripts? You define var enemyCount which is a builtin array that needs to be declared using:

enemyCount = new GameObject[<size>];

Builtin arrays are a fixed size defined at that point and can’t be resized. If that’s not done before you begin accessing enemyCount you’ll get an error like this.