private float spawnLimitXLeft = -22.0f; private float spawnLimitXRight = 7.0f; private float spawnPosY = 30.0f; private float startDelay = 1.0f; private float spawnInterval; // Start is called before the first frame update void Start() { InvokeRepeating("SpawnRandomBall", startDelay, spawnInterval); spawnInterval= Random.Range(3, 5); } // Update is called once per frame void Update() { } // Spawn random ball at random x position at top of play area void SpawnRandomBall () { int ballIndex =Random.Range(0, ballPrefabs.Length) ; // Generate random ball index and random spawn position Vector3 spawnPos = new Vector3(Random.Range(spawnLimitXLeft, spawnLimitXRight), spawnPosY, 0); // instantiate ball at random spawn location Instantiate(ballPrefabs[ballIndex], spawnPos, ballPrefabs[ballIndex].transform.rotation); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)