I have an array in my C# script
GameObjects[] gameObjects
and I have an object
GameObject myObject
I want to create a random number of elements in gameObjects array and add myObject to every element of the array (my object could be cube, sphere or anything) and then Instantiate it on screen. How can I do this?
I already have code below
public GameObject[] myObjects;
void Start()
{
float x = gameObject.GetComponent<Camera>().transform.position.x - Random.Range(100, 200);
float y = gameObject.GetComponent<Camera>().transform.position.y - Random.Range(50, 150);
float z = gameObject.GetComponent<Camera>().transform.position.z + 800;
Instantiate(myObjects[0], new Vector3(x, y, z), Quaternion.identity);
}
and it works perfectly but with this code, I may only add objects to the array from unity properties but I need to add elements from the code. I found nothing on the Internet about it.