I am trying to organize all my button texts into a neat array of arrays, I want the below to be put into a 6 element array but I cant get the syntax right.
public Text[] SwordTexts = new Text[6];
public Text[] ArmourTexts = new Text[6];
public Text[] StaffTexts = new Text[6];
public Text[] RingsTexts = new Text[6];
public Text[] AmuletTexts = new Text[6];
public Text[] CrystalTexts = new Text[6];
Then the array of arrays:
Text[,] AllTexts = new Text[6, 6];
Then in my start function:
Text [,] AllTexts = new Text[,]{SwordTexts, ArmourTexts, StaffTexts, RingsTexts, AmuletTexts, CrystalTexts};
This line gets “A nested array initializer was expected” and I don’t understand why
I think you must create the jagged array in Awake. This works.
using UnityEngine;
using UnityEngine.UI;
public class Neat : MonoBehaviour
{
public Text[] SwordTexts = new Text[6];
public Text[] ArmourTexts = new Text[6];
public Text[] StaffTexts = new Text[6];
public Text[] RingsTexts = new Text[6];
public Text[] AmuletTexts = new Text[6];
public Text[] CrystalTexts = new Text[6];
private Text[][] AllTexts;
void Awake()
{
AllTexts = new Text[][]
{
SwordTexts,
ArmourTexts,
StaffTexts,
RingsTexts,
AmuletTexts,
CrystalTexts
};
}
}
The C# documentation has the format for multidimensional array initializers: https://msdn.microsoft.com/en-us/library/aa664573(v=vs.71).aspx
int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
That format seems like it’ll be awkward for your data so I’d probably just set the indices manually:
Text[,] AllTexts = new Text[6, 6];
AllTexts[0] = SwordTexts;
etc.