- Home /
How to make an "on the run" generator?
I want to generate a simple map while the player moves, but I don't know how to do it.I want a simple map(to be honest it is only a path made with cubes, like in the Temple Run game, but just with cubes) and only need to generate turns. I want it to destroy the blocks which is not visible.
I tried to do it with cloning the cube, but I don't think I'm doing it in the right way. At least I don't know how to make it generate turns. Because of that I didn't finished the script.
NOTE: The player moves really fast so I need a fast generator.
using UnityEngine;
using System.Collections;
public class MapGenerator : MonoBehaviour {
float minute = Time.time;
public Transform tile;
public Transform player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
for (int x = 0; x < 100; x++)
{
Instantiate(tile, new Vector3(x, -6.785822f, -0.01354969f), Quaternion.identity);
}
float lastPos = 1;
if (lastPos == player.transform.position.x)
{
int type = Random.Range(0, 3);
if (type == 0)
{
if (minute < 10.0f)
{
float cameraPos = player.transform.position.x;
for (int needToGenerateLongime = 0; needToGenerateLongime <= 6; needToGenerateLongime++)
{
Instantiate(tile, new Vector3(cameraPos + needToGenerateLongime, -6.785822f, -0.01354969f), Quaternion.identity);
}
lastPos = cameraPos + 6.0f;
} else if (minute)
}
}
}
}
Comment