39 lines
951 B
GDScript
39 lines
951 B
GDScript
extends Node3D
|
|
|
|
@export var rat : Resource
|
|
@export var spawn_time_max = 5
|
|
|
|
var spawn_timer
|
|
var holes = []
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
#get holes
|
|
for node in self.get_children():
|
|
if node is RatHole:
|
|
holes.append(node)
|
|
print("HOLES : ",holes)
|
|
spawn_rat_at_random_hole()
|
|
reset_spawn_timer()
|
|
|
|
func _process(delta: float) -> void:
|
|
print("TIME UNTIL NEXT SPAWN : ",spawn_timer)
|
|
if spawn_timer > 0:
|
|
spawn_timer -= delta
|
|
else:
|
|
reset_spawn_timer()
|
|
spawn_rat_at_random_hole()
|
|
|
|
func spawn_rat_at_random_hole():
|
|
if holes.size() >= 2:
|
|
var hole_options = holes.duplicate()
|
|
hole_options.shuffle()
|
|
var spawn_hole = hole_options.pop_front()
|
|
var destination_hole = hole_options.pop_front()
|
|
print("SPAWN HOLE : ", spawn_hole)
|
|
print("END_HOLE : ",destination_hole)
|
|
spawn_hole.spawn_rat(destination_hole)
|
|
|
|
func reset_spawn_timer():
|
|
spawn_timer = randf_range(1,spawn_time_max)
|