Does anyone know, how I can create random generation with prefabs. Like so: I have 10 Prefabs. When I start the game, the first one should start at x=0, the second one at x=10m, and so on. How can I do that?
here you go ;o Code (CSharp): using UnityEngine; using System.Collections; public class RandomSpawn : MonoBehaviour { public int SpawnAmount = 50; [SerializeField] private GameObject[] PrefabArray; void Start() { int i = 0; while(i < SpawnAmount) { Vector3 newPosition = new Vector3(i * 10, 0, 0); Instantiate(PrefabArray[Random.Range(0, PrefabArray.Length)], newPosition, Quaternion.identity); i++; } } }
You should modify the Vector3 to take floats Code (CSharp): Vector3 newPosition = new Vector3(i * 10f, 0f, 0f);