Files
fps_project_1/scripts/Rat_Control.gd
2024-07-28 00:36:42 -05:00

35 lines
924 B
GDScript

extends Node3D
@export var rat : Resource
@export var spawn_amount = 10 #max amount in level at any given time
var rng = RandomNumberGenerator.new()
var holes = []
var start_hole_id
var start_hole
var end_hole_id
var end_hole
var hole_length_id
var control_node = self
# Called when the node enters the scene tree for the first time.
func _ready():
holes = get_children()
hole_length_id = holes.size() - 1
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if spawn_amount > 0:
start_hole_id = rng.randi_range(0,hole_length_id)
start_hole = holes[start_hole_id]
end_hole_id = rng.randi_range(0,hole_length_id)
while start_hole_id == end_hole_id:
end_hole_id = rng.randi_range(0,hole_length_id)
end_hole = holes[end_hole_id]
#spawn rat at first hole and pass position of next hole
start_hole.spawn_rat(end_hole,control_node)
spawn_amount -= 1