UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create 5 cube randomly"
using UnityEngine; public class RandomCubeSpawner : MonoBehaviour { public GameObject cubePrefab; public int numberOfCubes = 5; public float spawnRange = 10.0f; // Start is called before the first frame update void Start() { for (int i = 0; i < numberOfCubes; i++) { Vector3 randomPosition = new Vector3(Random.Range(-spawnRange, spawnRange), Random.Range(-spawnRange, spawnRange), Random.Range(-spawnRange, spawnRange)); Instantiate(cubePrefab, randomPosition, Quaternion.identity); } } }