Hello I have a question about unity 2d endless runner platform spawning... I made most of this things from a youtube tutorial (https://www.youtube.com/watch?v=NtY_R0g8L8E&t=684s)
When I start the game all of the platforms are spawning correctly but only a certain amount and they don't spawn when I get to the end of another platform ... It looks like just at the beginning of the script platforms are being spawned ): I tried all things I believe that could be the reason but NOTHING worked
Anyone know how to fix that?
CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TESTGAMEMANAGER : MonoBehaviour
{
private const float PLAYER_DISTANCE_SPAWN_LEVEL_PART = 50f;
[SerializeField] private Transform levelPart_Start;
[SerializeField] private List<Transform> levelPartList;
[SerializeField] private PlayerScript player;
private Vector3 lastEndPosition;
private void Awake()
{
lastEndPosition = levelPart_Start.Find("EndPoint").position;
int startingSpawnLevelParts = 5;
for (int i = 0; i < startingSpawnLevelParts; i++)
{
SpawnLevelPart();
}
}
private void Update()
{
if (Vector3.Distance(player.transform.position(), lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
{
// Spawn another level part
SpawnLevelPart();
}
}
private void SpawnLevelPart()
{
Transform chosenLevelPart = levelPartList[Random.Range(0, levelPartList.Count)];
Transform lastLevelPartTransform = SpawnLevelPart(chosenLevelPart, lastEndPosition);
lastEndPosition = lastLevelPartTransform.Find("EndPoint").position;
}
private Transform SpawnLevelPart(Transform levelPart, Vector3 spawnPosition)
{
Transform levelPartTransform = Instantiate(levelPart, spawnPosition, Quaternion.identity);
return levelPartTransform;
}
}
Let's create a Level Generator to make levels for a Infinite Endless Runner in Unity 2D.
✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=NtY_R0g8L8E
Endless Runner Level Generator (Difficulty + Highscores) in Unity https://www.youtube.com/watch?v=gsDSEUOLGHE
Simple Jump in Unity 2D
https://www.youtube.com/watch...