Hello, I’m learning to code and making a flappy bird inspired game. I have 2 different types of pipes, exactly the same just different colors. I want the game to spawn 1 of the 2 pipes at the time randomly. Any help or advice would be greatly appreciated.
public class PipeSpawner : MonoBehaviour
{
public float maxTime = 1.5f;
float timer = 0;
public GameObject Column;
public GameObject Column2;
public float minHeight;
public float maxHeight;
// Start is called before the first frame update
void Start()
{
GameObject newColumn = Instantiate(Column);
newColumn.transform.position = (Vector2)transform.position + Vector2.up * Random.Range(minHeight, maxHeight);
Destroy(newColumn, 5);
}
// Update is called once per frame
void Update()
{
if(timer > maxTime)
{
GameObject newColumn = Instantiate(Column);
newColumn.transform.position = (Vector2)transform.position + Vector2.up * Random.Range(minHeight, maxHeight);
Destroy(newColumn, 5);
timer = 0;
}
timer += Time.deltaTime;
}
}