Good evening all,
I’m trying to set up a script that spawns 4 random prefabs at 4 locations i have set up as spawn locations.
When I play the game, the objects all instantiate but two errors occur…
-
spawns 4 objects of the same color (but the color can change every time I rerun the game but still 4 of the same color)
-
they all spawn in the same location.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class BucketSpawn : MonoBehaviour {
[SerializeField] private GameObject[] spawnLocations; [SerializeField] private GameObject[] bucketPrefabs; private int bucketsOnScreen = 0; // Use this for initialization void Start () { int rndSpawnLocation = Random.Range(0, 3); int rndBucketSpawn = Random.Range(0, 3); while(bucketsOnScreen < 4) { Instantiate(bucketPrefabs[rndBucketSpawn], spawnLocations[rndSpawnLocation].transform); bucketsOnScreen++; } } // Update is called once per frame void Update () { }
}
i’ve literally spent hours trying to figure out whats going on, and why it wont actually fetch a position for each individual piece rather than obtaining a random position for everything and setting it for all 4 pieces. i’ve tweaked it so much that now I cant even get them to spawn on the screen anymore. any help would be greatly appreciated.