im trying to create a matrix and populate it with strings so i can manipulate it later, heres my code
using UnityEngine;
using System.Collections;
public class ScenarioMatrix : MonoBehaviour {
public GFRectGrid _grid;
public string[,] _scenarioArray;
/*
USAREMOS A SEGUINTE NOMECLATURA PARA O GRID
E = GRID VAZIO TEM SOMENTE O CENARIO
SP = Spawn Point, é onde o player começa
EP = é onde o player termina
L = Lajota é o caminho onde o player pode andar
CG = color get, é onde o bloco pega uma cor
CD = color drop é onde o bloco deixa a cor
*/
private string[] _values = {"E","SP","EP","L","CG","CD" };
// Use this for initialization
void Start() {
_scenarioArray = new string[(int)_grid.size.x, (int)_grid.size.z];
//montamos o array
for (int _largura = 1; _largura <= _grid.size.x; _largura++)
{
for (int _comprimento = 1; _comprimento <= _grid.size.z; _comprimento++)
{
string _valor = _values[Random.Range(0, _values.Length-1)];
_scenarioArray[_largura, _comprimento] = _valor;
//Debug.Log(_values[Random.Range(0, _values.Length)]);
}
}
Debug.Log(_scenarioArray);
}
// Update is called once per frame
void Update () {
}
}
So far im getting the error IndexOutOfRangeException: Array index is out of range. ScenarioMatrix.Start () (at Assets/Game/Scripts/ScenarioMatrix.cs:30)
what can i be doing wrong in this code?
(int)_grid.size.x, (int)_grid.size.zsizes?for (int _largura = 0; _largura < _grid.size.x; _largura++)andfor (int _comprimento = 1; _comprimento < _grid.size.z; _comprimento++)