Hello! I am new to Unity and I need help. I try to instantiate a prefab into anto an array of GameObjects and then use it from that array.
Here is my code:
public class TestScript : MonoBehaviour
{
public Transform somePrefab;
GameObject[] testArray;
void Start ()
{
testArray = new GameObject[5];
CreatingObjects ();
AssignNames ();
}
void CreatingObjects ()
{
for (int i = 0; i < 5; i++) {
testArray *= Instantiate (somePrefab) as GameObject; *
-
}*
-
}*
-
void AssignNames ()*
-
{*
-
for (int i = 0; i < 5; i++)*
_ testArray .name = "Cube # " + i;_
* }*
}
Probles is that I get an NullReferenceException error on line 28 (23 here):
*NullReferenceException: Object reference not set to an instance of an object
TestScript.AssignNames () (at Assets/Scripts/TestScript.cs:28)
TestScript.Start () (at Assets/Scripts/TestScript.cs:14)*
What am I doing wrong?