UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a unity script that will auto spawn blocks"
using UnityEngine; public class BlockSpawner : MonoBehaviour { public GameObject blockPrefab; public float spawnRate = 1f; public Vector3 spawnPosition; public Vector3 spawnRange; private float nextSpawnTime; // Start is called before the first frame update void Start() { nextSpawnTime = Time.time; } // Update is called once per frame void Update() { if (Time.time >= nextSpawnTime) { SpawnBlock(); nextSpawnTime = Time.time + spawnRate; } } void SpawnBlock() { Vector3 randomPosition = new Vector3( Random.Range(-spawnRange.x, spawnRange.x), spawnPosition.y, Random.Range(-spawnRange.z, spawnRange.z) ); Instantiate(blockPrefab, randomPosition, Quaternion.identity); } }