#Unity Endless Runner platforms not spawning automatically

1 messages · Page 1 of 1 (latest)

storm flame
#

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...

▶ Play video
#

if i increase that number more platforms will be spawned but just when I press play (start), when I reach the end they aren't spawning automatically

storm flame
#

i made that i can spawn platforms by pressing a button but if i am not doing this constant there is a gap

#

):

#

when they spawned i pressed a button

#

it's not going automatically

covert hare
#

@storm flame do you understand the code you've written?

storm flame
#

I did yes

covert hare
#

Okay

storm flame
#

but bc it not worked i copied the one from the tutorial

#

still not

covert hare
#

Okay

#

Well, don't do that because code is copyrighted

storm flame
#

oh

#

but it's my private game

covert hare
#

Okay

#

Depending on what the creator allows with the use of their code, they can come after you.

#

But if it's privately then it should be fine

storm flame
#

well.. i just tried to make a game 😄 for fun but now the platform spawning is not working

covert hare
#

I'll try and help

#

Geez

storm flame
#

tell me when you need information

#

about sth

covert hare
#

I mean I'm still slowly learning myself.

#

But more minds is better

storm flame
#

yeye

#

that's my first try in coding anyway

covert hare
#

Code does also get outdated

storm flame
#

what does that mean?

covert hare
#

Well, code gets updated

#

New functions are created and removed

#

Things change

storm flame
#

okay

covert hare
#

It's an older tutorial

#

That's why I'm saying this

#

But it should still work

storm flame
#

ohh so things from the tutorial don't work anymore?

#

ahh

#

should I send screenshots?

#

from code

#

then it's easer to read

#

maybe

covert hare
#

No

#

It's fine

storm flame
#

this level parts?

#

ok

covert hare
#

I think the code should work

#

No

storm flame
#

ye, I don't know why the platforms aren't spawning

covert hare
#

In the code

storm flame
#

ahh

covert hare
#

It's a list of transforms

storm flame
#

okie

covert hare
#

So how many objects spawn on the start if the game?

#

5?

storm flame
#

wait

#

you're right it should be always 5 parts

#

but when I incresase this number more are spawned

#

there it is on 200

covert hare
#

Okay

#

Oh yea screenshot is much easier to read

#

Wait so if you hit p it spawns more tiles?

storm flame
#

i made that to check

#

if it's working

covert hare
#

Okay

#

Well if the 200 is the problem

#

Thats the only place I can find where it's used

#

So...

#

Correct?

storm flame
#

yes

covert hare
#

So how many tiles is it supposed to spawn each time?

storm flame
#

of quality

covert hare
#

Thanks

storm flame
covert hare
#

what is the EndPoint?

#

Okay

storm flame
#

wait

#

endpoint is this object at the end of each tile

covert hare
#

Okay

#

You have 2 SpawnLevelPart() at the bottom

#

One is returning a transform and takes 2 peramiters

#

I dont see you ever calling the 2nd one

storm flame
#

this one?

covert hare
#

Oh wait

#

Nvm sorry

#

Your calling it and passing in both peramiters

#

Right there

#

So you are calling it

storm flame
#

ye so the code should work, but why the platforms don't spawn ):
Could it be the reason that the player can't see anything or sth other?

covert hare
#

No

#

I don't think so

#

I would go and make sure you didn't mix anything up

#

Go ever it again and see if there are any differences

storm flame
#

with mine and the one from the tutorial?

covert hare
#

Well both

#

For example

#

Make sure that is a less then

storm flame
#

ohh right I will try

covert hare
#

It is currently, but it's things like that that can completely screw it up

#

I dont really know, my mind isn't ready for big things like this yet. It's still the morning for me 😆

storm flame
#

Yeah me too ;D

hot thunder
#

hey how do you create a separate chatroom like this from the main room? also it got to do with your if section in your update that you are not spawning

storm flame
#

Oooof MY HEAD IS BURNING NOW
I gave the turtle controls (left, right, jump) so that the ground is standing still and the turtle is moving and now the ||fucking|| platforms are spawning!!!! ahhhh

hot thunder
#

hey thanks. how do i direct people to the thread?

storm flame
#

lol

#

just do

#

"#

#

ahh

#

type the name after this "#"

hot thunder
storm flame
#

yeah so it works

hot thunder
#

ah sweet

#

you fixed your issue?