Hi! I'm making a space invasion type of game, and in it i have an enemy spawner and a pause button/system. The pause system works, but it only pauses 2D physics and input events, which doesnt stop the enemies from spawning.
This is my spawner script:
func _ready():
var rand = RandomNumberGenerator.new()
var enemyalien = load("res://mobs/alienyellow.tscn")
var screen_size = get_viewport().get_visible_rect().size
var time = true
var tic = 1
for i in range(0, 100000):
var alien = enemyalien.instance()
rand.randomize()
var x = rand.randf_range(0+16, screen_size.x-16)
var y = -39
alien.position.x = x
alien.position.y = y
add_child(alien)
time = false
yield(get_tree().create_timer(rand_range(1, 2)), "timeout")
time = true
As you can see,it's in the " _ready(): " function
This is the pause button script:
func _input(event):
if Input.is_key_pressed(KEY_P):
$Background.visible = !$Background.visible
get_tree().paused = !get_tree().paused
My question is, when the P button is pressed,how can i stop the enemies from spawning as well? I hope that i gave enough information and that i explained the problem successfully!