Advertisement
opaBR

[FUNC] Spawner

Feb 3rd, 2021
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Position2D
  2.  
  3. export (PackedScene) var spawnScene
  4. onready var spawnReference = load(spawnScene.get_path())
  5.  
  6. export (NodePath) var timerpath
  7. onready var timerNode = get_node(timerpath)
  8.  
  9. export(float) var minTimeWait
  10. export(float) var maxTimerWait
  11. func _ready():
  12.     randomize()
  13.     timerNode.set_wait_time(rand_range(minTimeWait, maxTimerWait))
  14.     timerNode.start()
  15.  
  16. func _on_Timer_timeout():
  17.     var spawnInstance = spawnReference.instance()
  18.     get_parent().add_child(spawnInstance)
  19.     spawnInstance.set_global_position(get_global_position())
  20.    
  21.     timerNode.set_wait_time(rand_range(minTimeWait, maxTimerWait))
  22.     timerNode.start()
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement