UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a cube that will auto spawn"
using UnityEngine; public class AutoSpawnCube : MonoBehaviour { public GameObject cubePrefab; public float spawnInterval = 1f; // Start is called before the first frame update void Start() { InvokeRepeating("SpawnCube", 0f, spawnInterval); } void SpawnCube() { // Set a random position for the cube Vector3 spawnPosition = new Vector3(Random.Range(-5f, 5f), Random.Range(1f, 5f), Random.Range(-5f, 5f)); // Instantiate the cube at the random position Instantiate(cubePrefab, spawnPosition, Quaternion.identity); } }