bullet_spawner.gd 361 B

123456789101112131415161718
  1. extends Node2D
  2. var bullet = preload("Bullet.tscn")
  3. func _unhandled_input(event):
  4. if event.is_action_pressed("fire"):
  5. fire()
  6. func fire():
  7. if not $CooldownTimer.is_stopped():
  8. return
  9. $CooldownTimer.start()
  10. var new_bullet = bullet.instantiate()
  11. add_child(new_bullet)
  12. new_bullet.position = global_position
  13. new_bullet.direction = owner.look_direction