To get straight to the point, I’m a noob.
Trying to learn both Unity and C# at the same time.
Working on a code that will create infinite endless runner by using my prefabs as the ground.
I was thinking of using an emptyObject at the end of each prefab that will be the mark for where the new prefab should start. I’ve googled the whole day, periodically of course, but cannot find the right call or the right way to instantiate the prefab at the end of anotherone unless they are all completely the same size.
heres the code I jumbled up together
public class InfinitePlanes : MonoBehaviour
{
public Transform endPos;
public int lastPos;
public GameObject[] RoadPrefabs;
public int objectsSpawned = 0;
private void Update()
{
//if //Help (lastPos choose highest int) OR should I
objectsSpawned = objectsSpawned + 1;
Instantiate(RoadPrefabs[Random.Range(0, RoadPrefabs.Length)], new Vector3 //HELP endPos.position.x, startPos.position.y, transform.position.z) Quaternion.Identity;
}
}
Should I scrap the way Im trying to do this? Im trying to refrain from having every prefab be the same size.
Thanks in advance
also, I know this will run on forever. I thought once I have the tiles spawning the right way I can limit it to spawning only a handful at a time, with a collisionzone that will deactivate the prefab after the player left it after a set number of seconds. Im pretty sure I know how to do that. Ive done something similar before.