How do you make a copy of a 2D array of GameObjects (made from instantiated prefabs) in another script. The array I want to copy is pieces[8,8] in GameManager.cs.
I have tried:
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (GameManager.instance.pieces [i, j] != null) {
GameObject temp = new GameObject();
pieces[i,j] = GameManager.instance.pieces[i, j];
}
}
}
and
private GameObject[,] pieces
pieces = new GameObject[8,8];
pieces = GameManager.instance.pieces.Clone();
and many, many other ideas...
The issue is a NullReferenceException anytime one of the "copied" GameObjects is used in any method.
Thanks in advance.
↧