- Home /
Index out of range exception - C# - Can't find the problem
I can't find the problem in this code. It always says that my Array index is out of range.
I have 2 scripts:
using UnityEngine;
using System.Collections;
public class World : MonoBehaviour {
public static World currentWorld;
public int chunkWidth = 10, chunkLength = 10, chunkHeight = 0, seed = 0;
// Use this for initialization
void Awake () {
currentWorld = this;
if (seed == 0)
seed = Random.Range(0, int.MaxValue);
}
// Update is called once per frame
void Update () {
}
}
And this one:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Chunk : MonoBehaviour {
private Vector3[,,] map;
MeshRenderer meshRenderer;
MeshCollider meshCollider;
MeshFilter meshFilter;
public GameObject prefab;
// Use this for initialization
void Start () {
meshRenderer = GetComponent<MeshRenderer>();
meshCollider = GetComponent<MeshCollider>();
meshFilter = GetComponent<MeshFilter>();
map = new Vector3[World.currentWorld.chunkLength, World.currentWorld.chunkHeight, World.currentWorld.chunkWidth];
for (int x = 0; x < World.currentWorld.chunkLength; x++)
{
for (int z = 0; z < World.currentWorld.chunkWidth; z++)
{
Instantiate (prefab, map[x, 0, z], Quaternion.identity);
}
}
}
// Update is called once per frame
public void CreateVisualMesh ()
{
}
}
Any help is appreciated.
Comment
Your answer
Follow this Question
Related Questions
Array Index out of range (JavaScript) 1 Answer
System.Array.IndexOf 1 Answer
Array Index Out of Range 2 Answers
OnGui function - Array is out of index question 1 Answer
Arrays rebels to my power! 1 Answer