ball_factory.gd 434 B

12345678910111213141516
  1. extends Node2D
  2. @export var ball_scene: PackedScene = preload("res://ball.tscn")
  3. func _unhandled_input(event):
  4. if event.is_echo():
  5. return
  6. if event is InputEventMouseButton and event.is_pressed():
  7. if event.button_index == MOUSE_BUTTON_LEFT:
  8. spawn(get_global_mouse_position())
  9. func spawn(spawn_global_position):
  10. var instance = ball_scene.instantiate()
  11. instance.global_position = spawn_global_position
  12. add_child(instance)