DonutSpawner.gd 512 B

123456789101112131415161718192021222324252627282930
  1. extends Spatial
  2. var donutScene = load("res://FlyingDonut.tscn")
  3. var period = 0.2
  4. var r_max = 10
  5. var r_min = 5
  6. func _ready():
  7. randomize()
  8. var timer = Timer.new()
  9. timer.wait_time = period
  10. timer.connect("timeout",self,"_on_timeout")
  11. add_child(timer)
  12. timer.start()
  13. func _on_timeout():
  14. var phi = rand_range(0,2*PI)
  15. var r = rand_range(r_min,r_max)
  16. spawn_donut(Vector3(r*cos(phi),0,r*sin(phi)))
  17. func spawn_donut(vec):
  18. var donut = donutScene.instance()
  19. donut.translation = vec
  20. add_child(donut)