In my flappy bird game, I want to create a loop that works through instantiated pipes, altering the pipe prefab (to reduce space between pipes + increase respawn rate) to increase difficulty based on player score.
The code below works, but I'd like to implement difficulty differently. I don't know how to add newly instantiated objects to a list.
I'd also like to add an event animation that plays after each level (before new pipe prefab instantiated), pausing the loop as the "new level" text flies across the screen.
private void Start()
{
InvokeRepeating("SpawnPipe", .05f, respawnRate);
}
private void SpawnPipe()
{
int levelOne = 8;
int levelTwo = 18;
int levelThree = 29;
if(GameManager.score < levelOne)
{
GameObject pipes1 = Instantiate(pipePrefab1, transform.position, Quaternion.identity);
pipes1.transform.position += Vector3.up * Random.Range(minHeight, maxHeight);
}
if (GameManager.score > levelOne && GameManager.score < levelTwo)
{
GameObject pipes2 = Instantiate(pipePrefab2, transform.position, Quaternion.identity);
pipes2.transform.position += Vector3.up * Random.Range(minHeight, maxHeight);
}
if (GameManager.score > levelTwo && GameManager.score < levelThree)
{
GameObject pipes3 = Instantiate(pipePrefab3, transform.position, Quaternion.identity);
pipes3.transform.position += Vector3.up * Random.Range(minHeight, maxHeight);
}
}