Array won't be filled by Instantiate

Hi guys (and girls ;)),

I just started using Untity and atm I’m fooling around a bit.
In this case I’m trying to instantiate grassPrefabs and manage them in an array so I can always check if the player is too far from the grass and it shouldn’t be rendered to save ressources, but somehow the array I’m creating stays empty.

I guess the important part is the very last line.

Ty for your help,


#pragma strict

//Normales Gras
public var Gras1Prefab : Transform;
var grasArray : GameObject[];

//Spieler erstellen
public var PlayerPrefab : Transform;
var iPlayerPrefab : GameObject;

//Level innitiieren.
var newLevel = 1;
public static var GrasColor:Color = new Color(0f, 1f, 0f, 1f);
var mapX : int;
var mapZ : int;

function Start () {


function Update () {
	//Lade neue Level

	if (newLevel==1){
		iPlayerPrefab = GameObject.Find("PlayerPrefab");
		var filePath = Application.dataPath + "/Resources/Textures/Level/Level1.png";
  	  	if (System.IO.File.Exists(filePath)){
		   	var bytes = System.IO.File.ReadAllBytes(filePath);
		   	var tex = new Texture2D(1, 1);
		   	iPlayerPrefab.transform.position = Vector3 (5,5,5);
		   	transform.localScale += Vector3(tex.width ,0,tex.height);
		   	transform.localPosition += Vector3(tex.width/2,0,tex.height/2);
		   	//Erstellung von "Normales Gras
		   	grasArray = Array(tex.width*tex.height);	
		   	for(var x=0; x<tex.width; x++){
		   		for(var z=0;z<tex.height; z++){
		  			var pixel:Color = tex.GetPixel(x, z);
		   			if (pixel==GrasColor){	//Normales Gras
		   				grasArray[x+(tex.width*z)] = Instantiate (Gras1Prefab, Vector3(x,1,z), Gras1Prefab.transform.rotation) as GameObject;

I am not so used to UnityScript anymore but I would think you need to instantiate your array. You have a reference for an array of type GameObject but you never tell how many spot it should have:

var grasArray = new GameObject;

The big advantage of UnityScript over C# is that it does not seem to let you know you are doing wrong and then you are up for some long hours while C# would have told you right on that this array is not existing.