using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager : MonoBehaviour { public GameObject block; public float maxX; public Transform spawnPoint; public float spawnRate; bool gameStarted = false; // Update is called once per frame void Update() { if(Input.GetMouseButtonDown(0) && !gameStarted ) { StartSpawning(); gameStarted= true; } } private void StartSpawning() { InvokeRepeating("SpawnBlock", 0.5f, spawnRate); } private void SpawnBlock() { Vector3 spawnPos = spwanPoint.position; spawnPos.x = Random.Range(-maxX, maxX); Instantiate( block, spawnPos, Quaternion.identity ); } }
public Transform spawnPoint;
Vector3 spawnPos = spwanPoint.position;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)