generated from krampus/template-godot4
23 lines
563 B
GDScript3
23 lines
563 B
GDScript3
|
extends Node3D
|
||
|
|
||
|
const BALL_SPAWN_GROUP := "BallSpawn"
|
||
|
|
||
|
@export var ball_scene: PackedScene
|
||
|
|
||
|
|
||
|
func spawn_balls() -> void:
|
||
|
for spawn: Node3D in get_tree().get_nodes_in_group(BALL_SPAWN_GROUP):
|
||
|
var ball: GameBall = ball_scene.instantiate()
|
||
|
var callback := func() -> void:
|
||
|
if ball.sleeping:
|
||
|
ball.queue_free()
|
||
|
ball.sleeping_state_changed.connect(callback)
|
||
|
spawn.add_sibling(ball)
|
||
|
ball.global_transform = spawn.global_transform
|
||
|
ball.freeze = false
|
||
|
|
||
|
|
||
|
func _process(_delta: float) -> void:
|
||
|
if Input.is_action_just_pressed("debug_1"):
|
||
|
spawn_balls()
|