After days of looking for solutions, what's wrong with my array script?

I’ve tried multiple ways of writing the syntax. I’m on the verge of leaving Arrayl̶i̶s̶t̶ for rigid solutions and using list for more flexibility. Yet I have to solve this one or else I’ll feel like I’ve failed. Please help.

Only one object gets spawned and the array length stays zero.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class isolatingproblems : MonoBehaviour {

	public GameObject cube;

	int limit = 9;

	public GameObject[] arrcube;

	void spawn () 
		for (int i = 0; i < limit; i++) 
			GameObject cubearray = Instantiate (cube, transform.position, Quaternion.identity);

			arrcube *= cubearray;*
  •  }*
  • }*

  • void Update ()*

  • {*

  •  if (Input.GetButtonDown ("Jump"))* 
  •  {		*
  •  	spawn ();*
  •  }*
  • }*

you need to initialize the array with

arrcube = new GameObject[limit];

before you can put anything into the array.
Once you call that, you get an array with 9 null elements, so you need should put it in the start method.

you didn’t initialize arrcube… in your case that would

arrcube = new GameObject[9];

Then you can iterate thorugh the for loop like this:

for (int i = 0; i < arrcube.length; i++) 

Also you can use a

List<GameObject> arrcube = new List<GameObject>();

if you want the array to be flexible in size. (to hold more or less than 9).

To add a Gameobject to arrcube you’d then need to use: