How to instantiate different scenes for an endless runner?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LyguN

So currently im instantiating the same ground Scene everytime, whereas I wan’t to randomly spawn different scenes from a list.

Here is how my script looks right now:

const ground = preload("res://Scenes/Walls&Floors/Floor1.tscn")
const groundDistance = 250

var groundSpawnPosition = global_position

onready var player = get_parent().get_node("Player")
onready var floorContainer = get_parent().get_node("EnvironMent/Floors")

func _process(_delta):
    if groundSpawnPosition.distance_to(player.global_position) < 1000:

func spawnGround():
    var spawnInstance = ground.instance()
    spawnInstance.global_position = Vector2(-380, groundSpawnPosition.y)
    groundSpawnPosition.y = groundSpawnPosition.y + groundDistance

randomly scene instance ?

ramazan | 2021-12-22 18:49

:bust_in_silhouette: Reply From: Inces
var rand -

var scenelist = ["wallsandfloors","thepit","labirynth","blabla"]
var randompickup = scenelist[rand.randirange(0,scenelist.size()-1)]
var scene = load("res://Scenes/" + randompickup + ".tscn")
var inst = scene.instance()

You just have to keep your scenes in one directory

Thank You!!!

LyguN | 2021-12-22 21:22