When I run my game in editor I get this error
NullReferenceException: Object reference not set to an instance of an object (wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
It is an error in this javascript script:
#pragma strict
public var data : byte[,,];
public var worldX : int = 16;
public var worldY : int = 16;
public var worldZ : int = 16;
function Start () {
data = new byte[worldX, worldY, worldZ]; //an error is made for this line
for(var x : int = 0; x < worldX; x++){
for(var y : int = 0; y < worldY; y++){
for(var z : int = 0; z < worldZ; z++){
if(y <= 8){
data[x,y,z] = 1;
}
}
}
}
}
function Block(x : int, y : int, z : int) : byte{
if( x >= worldX || x < 0 || y >= worldY || y < 0 || z >= worldZ || z<0){
return 1;
}
return data[x,y,z];
}
but I found out that an error is acquired only if I run function GenerateMesh in other script where I use function Block from first script. This is the part of script where I use Block function:
function GenerateMesh() {
for(var x : int = 0; x < chunkSize; x++){
for(var y : int = 0; y < chunkSize; y++){
for(var z : int = 0; z < chunkSize; z++){
if(world.Block(x, y, z) != 0){
if(world.Block(x, y + 1, z) == 0){
CubeTop(x, y, z, world.Block(x, y, z));
}
if(world.Block(x, y - 1, z) == 0){
CubeBot(x, y, z, world.Block(x, y, z));
}
if(world.Block(x + 1, y, z) == 0){
CubeEast(x, y, z, world.Block(x, y, z));
}
if(world.Block(x - 1, y, z) == 0){
CubeWest(x, y, z, world.Block(x, y, z));
}
if(world.Block(x, y, z + 1) == 0){
CubeNorth(x, y, z, world.Block(x, y, z));
}
if(world.Block(x, y, z - 1) == 0){
CubeSouth(x, y, z, world.Block(x, y, z));
}
}
}
}
}
}
I just cant figure out what wrong. Any help is appreciated.