- Home /
Question by
Ginxx009 · Jun 27, 2018 at 06:48 AM ·
c#prefabsmultidimensional array
Instantiate prefab base on the value of multidimensional array (C# UNITY)
Hello guys I just wanted to ask if it is possible to instantiate prefab base on the value of your Multidimensional Array
for example I have this data.
10 20 11
00 21 10
00 00 00
00 00 00
00 00 00
00 00 00
Now here is my code
string road1 = "";
for (int y = 0; y < bsb.ArrBigRoad.GetLength(0); y++)
{
for (int x = 0; x < bsb.ArrBigRoad.GetLength(1); x++)
{
road1 += string.Format("{0:D2}", bsb.ArrBigRoad[y, x] / 100);
road1 += ".";
}
road1 += "\n";
}
Debug.Log(road1);
Right now I am printing it using Label
like this
[SerializeField] public UILabel info_scores_bigroad;
info_scores_bigroad.text = road1;
Comment
Answer by Glurth · Jun 27, 2018 at 03:12 PM
Yes. Attach a monobehavior based script to the prefab in question, add a Start() function to it, and put your initilization code in there. Now when the pre-fab is instantiated, the Start() code will run automatically. (https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html)
Note: This does require that your script be able to access the initialization data (your multi-dim array).