Hi guys, I’m trying to Instantiate a set of objects whenever a Space is pressed and store them into currentObj array so I can access them later. But I keep getting problem where the rest of currentObj array are null except for the last index.
Here is my code:
public GameObject[] obj;
public GameObject spawnObj;
public GameObject[] currentObj;
Vector3 spawnPoint;
void Start(){
spawnPoint = transform.position;
}
void Update(){
if (Input.GetKeyDown (KeyCode.Space)) {
for (int i = 0; i< 10; i++) {
currentObj = new GameObject[10];
spawnObj = (GameObject)Instantiate (obj [(int)Random.Range (0, obj.Length)], spawnPoint, Quaternion.identity) as GameObject;
currentObj *= spawnObj.gameObject;*
-
Debug.Log(i);*
-
spawnPoint.x = spawnPoint.x + 1.2f;*
-
}*
-
}*
}
}
Any help on this would be greatly appreciated! Thank you.