Making an endless hallway with random objects spawning
I am trying to do three things,
1.Have an endless hallway
2.Have random prefabs/objects spawn along the hallway
3.Have objects replaced by new objects to make it seem like a different part of the hallway
I have already created a endless hallway by simply teleporting the player back to the beginning of the hallway to a create loop, However I wanna make it so each time the player is teleported back to the beginning the old objects are replaced by new objects in the set areas. (Making it seem like a different part of the hallway)
Teleporting Script:
using UnityEngine;
using System.Collections;
public class TeleportPad : MonoBehaviour {
public int code;
float disableTimer = 0;
void Update() {
if (disableTimer > 0)
disableTimer -= Time.deltaTime;
}
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.name == "player" && disableTimer<=0)
{
foreach(TeleportPad tp in FindObjectsOfType<TeleportPad>())
{
if (tp.code==code && tp != this)
{
tp.disableTimer = 2;
Vector3 position = tp.gameObject.transform.position;
position.y += 1;
collider.gameObject.transform.position = position;
}
}
}
}
}
Here's also an example script I tried using to spawn the objects in the hallway. I only was able to spawn one object and I had no idea how to remove the clones and create new ones.
RandomObject Placement Script:
using UnityEngine;
using System.Collections;
public class TeleportPad : MonoBehaviour {
public int code;
float disableTimer = 0;
void Update() {
if (disableTimer > 0)
disableTimer -= Time.deltaTime;
}
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.name == "player" && disableTimer<=0)
{
foreach(TeleportPad tp in FindObjectsOfType<TeleportPad>())
{
if (tp.code==code && tp != this)
{
tp.disableTimer = 2;
Vector3 position = tp.gameObject.transform.position;
position.y += 1;
collider.gameObject.transform.position = position;
}
}
}
}
}
Thanks to anyone who is able to help with this. I just started using Unity a month ago so any simple/easy to understand fixes would be nice. Thank you!