I'm attempting to make a 3D Endless Runner-type game. The pathway is 5 blocks wide and 1-4 of the 5 blocks need to generate every 50 units on the Z axis so the player has a way to proceed.
So far, I've been making each combination (31 of them) get chosen from an existing prefab, but making each combination separately is a bit of a pain. Not to mention it takes up more memory then id like it to.
Is there a way to have the blocks generate randomly across the X-Axis every 50 units along the Z-Axis?
Here's the code I've been using so far. (Just figured out how to post it)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenerateLevel : MonoBehaviour
{
public GameObject[] section;
public int zPos = 50;
public bool creatingSection = false;
public int secNum;
void Update()
{
if (creatingSection == false)
{
creatingSection = true;
StartCoroutine(GenerateSection());
}
}
IEnumerator GenerateSection()
{
secNum = Random.Range(0, 31);
Instantiate(section[secNum], new Vector3(0, 0, zPos), Quaternion.identity);
zPos += 50;
yield return new WaitForSeconds(2);
creatingSection = false;
}
}