I'm creating chess in unity, and I want to create the chess board using a 2D array of cells. I was able to create an array of pieces and could reference them with their respective prefabs in Unity. But I have no option to reference the 2D array.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gameManager : MonoBehaviour
{
public GameObject[,] cell = new GameObject[7,7];
public GameObject[] Wpawn = new GameObject[7];
public GameObject[] Bpawn = new GameObject[7];
public GameObject[] Wrook = new GameObject[1];
public GameObject[] Brook = new GameObject[1];
public GameObject[] Wknight = new GameObject[1];
public GameObject[] Bknight = new GameObject[1];
public GameObject[] Wbishop = new GameObject[1];
public GameObject[] Bbishop = new GameObject[1];
public GameObject Wking;
public GameObject Bking;
public GameObject Wqueen;
public GameObject Bqueen;
bool[] Bpawn2 = new bool[7];
bool[] Wpawn2 = new bool[7];
short turn = 0;
// Start is called before the first frame update
void Start()
{
#region Board
for (float y = 0F; y <= 7; y+= 1)
{
for (float x = 0F; x <= 7F; x+= 1)
{
if (y % 2 == 0)
{
if (x % 2 == 0)
{
cell[(int)x,(int)y].GetComponent<SpriteRenderer>().color = Color.gray;
} else if (x % 2 == 1)
{
cell[(int)x,(int)y].GetComponent<SpriteRenderer>().color = Color.white;
}
} else if (y % 2 == 1)
{
if (x % 2 == 0)
{
cell[(int)x,(int)y].GetComponent<SpriteRenderer>().color = Color.white;
} else if (x % 2 == 1)
{
cell[(int)x,(int)y].GetComponent<SpriteRenderer>().color = Color.gray;
}
}
Instantiate(cell[(int)x,(int)y], new Vector3(x - 3.5F, y -3.5F), transform.rotation);
}
}
#endregion
}
}
As you can see I've properly initialized my 2D array. I only showed you the setboard Region because there were no problems in the rest.
Here is the gamemanager script component and what it is showing me.
There is no option to reference the Cell Prefab