spawning chests in csg boxes, working on making them root of scene so they aren't cleared with the scene on exit
This commit is contained in:
24
scripts/sublevel.gd
Normal file
24
scripts/sublevel.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends Node3D
|
||||
|
||||
const CHEST_1 = preload("res://chest1.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
spawn_chests()
|
||||
|
||||
func spawn_chests():
|
||||
var chest_spawners = get_tree().get_nodes_in_group("chest_spawner")
|
||||
|
||||
|
||||
if chest_spawners.size() > 0:
|
||||
for i in chest_spawners:
|
||||
i.visible = false
|
||||
|
||||
var number_chests = 3
|
||||
|
||||
while number_chests > 0:
|
||||
var chest_loc = chest_spawners.pick_random()
|
||||
var instance_chest = CHEST_1.instantiate()
|
||||
get_tree().current_scene.add_child(instance_chest)
|
||||
instance_chest.global_position = chest_loc.global_position + chest_loc.random_box_pos()
|
||||
print("CHEST SPAWNED AT : ",instance_chest.global_position)
|
||||
number_chests -= 1
|
||||
Reference in New Issue
Block a user