private int spawnWalls(int i, int currentTotalWalls) { // control the speed variable if (currentTotalWalls == 1) { currentWallSpeed = 0.1f; } else if (currentTotalWalls % 5 == 0) { currentWallSpeed = currentWallSpeed + 0.07f; } setRespawnTime(Random.Range(1.5f, 4.0f)); // Spawn wall and obstacle N times where N times is requried to be set; if ((i % 2) == 0) { // increment walls only when wall is spawned currentTotalWalls++; randWall = Random.Range(1, 4); // adds random walls to the scene and assign speed as each object is instantiated if (randWall == 1) { GameObject a = Instantiate(wallBasic1) as GameObject; a.transform.position = new Vector3(-1.193203f, 6.31f, 92f); WallScript ws = a.GetComponent <WallScript>(); ws.setWallSpeed(currentWallSpeed); } else if (randWall == 2) { GameObject a = Instantiate(wallBasic2) as GameObject; a.transform.position = new Vector3(-5.893f, 6.31f, 92f); WallScript ws = a.GetComponent <WallScript>(); ws.setWallSpeed(currentWallSpeed); } else if (randWall == 3) { GameObject a = Instantiate(wallBasic3) as GameObject; a.transform.position = new Vector3(3.158229f, 6.31f, 92f); WallScript ws = a.GetComponent <WallScript>(); ws.setWallSpeed(currentWallSpeed); } } else { // adds ball obstacle to the scene in random x location. float randomX = Random.Range(-7f, 7f); GameObject obstacle = Instantiate(ballObject) as GameObject; obstacle.transform.position = new Vector3(randomX, 5f, 90f); ObstacleScript os = obstacle.GetComponent <ObstacleScript>(); os.setObstacleSpeed(currentWallSpeed); } return(currentTotalWalls); }