godot-demo-projects/misc/instancing/ball_factory.gd

17 lines
424 B
GDScript3
Raw Normal View History

2020-02-02 10:37:15 +01:00
extends Node2D
2020-02-02 10:37:15 +01:00
export(PackedScene) var ball_scene = preload("res://ball.tscn")
func _unhandled_input(event):
if event.is_echo():
return
if event is InputEventMouseButton and event.is_pressed():
if event.button_index == BUTTON_LEFT:
spawn(get_global_mouse_position())
2020-02-02 10:37:15 +01:00
func spawn(spawn_global_position):
var instance = ball_scene.instance()
instance.global_position = spawn_global_position
add_child(instance)