25 lines
657 B
GDScript
25 lines
657 B
GDScript
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
|