Greetings
I am trying to write a script to randomly position “all gameObjects” in an array onto the stage every time stage restarts, using preset locations.
These are the scripts I have so far.
any help will be much appreciated
public class Random_position : MonoBehaviour
{
public GameObject itemToSpread;
public GameObject[] itemsToPickFrom;
public Vector3[] position;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < itemsToPickFrom.Length; i++)
{
SpreadItem();
}
}
void SpreadItem()
{
//Vector3 randomPosition = new Vector3();
int randomIndex_location = Random.Range(0, position.Length);
//GameObject clone = Instantiate(itemToSpread, randomPosition, Quaternion.identity);
GameObject clone = Instantiate(itemToSpread, position[randomIndex_location], Quaternion.identity);
}
void Pick()
{
int randomIndex = Random.Range(0, itemsToPickFrom.Length);
//int randomIndex_location = Random.Range(0, position.Length);
GameObject clone = Instantiate(itemsToPickFrom[randomIndex], transform.position, Quaternion.identity);
}
}