void SpawnBall() { if (activeBalls.Count >= maxBallsOnScreen) { return; // don't spawn a new ball if there are too many already } // Create and set up a new ball float scale = UnityEngine.Random.Range(minScale, maxScale); int ballSlot = GetNewBallSlot(); Vector2 position = new Vector2(GetXPosByBallSlot(ballSlot), UnityEngine.Random.Range(-maxYDistFromHorizontal, maxYDistFromHorizontal)); GameObject ball = (GameObject)Instantiate(ballPrefab, position, Quaternion.identity); CircleControl control = ball.GetComponent <CircleControl>(); ball.GetComponent <SpriteRenderer>().color = ballColours[Random.Range(0, ballColours.Length)]; // assign a random colour control.SetupScale(scale); // assign a random scale control.Freeze(); control.ballSlot = ballSlot; activeBalls.Add(ball); activeBallColliders.Add(control.tapCollider); ball.GetComponent <BallAccessories>().AddRandomAccessory(); // some balls recieve a random accessory ballsSpawned++; if (ballsSpawned == 2) { if (gameMode == Mode.Timed) { UIController.ShowTutorialText("MORE BALLS = MORE POINTS"); UIController.Invoke("HideTutorialText", UIController.tutorialDisplayTime); } } sfx.Play(sfx.pop); }