Hello everyone, I’m making a game similar to Flappy bird. I have already made one type of obstacles, that is, their appearance at a random height. But I would also like to introduce several varieties of these barriers, that is, the periodic appearance of each of their varieties. How to do this, please tell me.
P.S. Below I will attach the code where I registered the random height of the barrier spawn.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipe_pawner : MonoBehaviour
{
public float maxTime = 1;
private float timer = 0;
public GameObject pipe;
public float height;
void Start()
{
GameObject newpipe = Instantiate(pipe);
newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
}
void Update()
{
if(timer > maxTime)
{
GameObject newpipe = Instantiate(pipe);
newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
Destroy(newpipe, 15);
timer = 0;
}
timer += Time.deltaTime;
}
}