extends Node3D
class_name Particle

var life_time : float
var is_pause : bool = false
var particle_list : Array[GPUParticles3D]
var speed_scale_list = []

func _ready():
	for child in get_children():
		if child is GPUParticles3D:
			var particle = child as GPUParticles3D
			particle_list.append(particle)
			speed_scale_list.append(particle.speed_scale)
	for particle : GPUParticles3D in particle_list:
		if particle.lifetime > life_time:
			life_time = particle.lifetime
		particle.restart()

func _process(delta):
	if is_pause:
		return
	life_time -= delta
	if life_time <= 0:
		queue_free()

func set_pause(is_pause_set:bool):
	is_pause = is_pause_set
	for i in range(len(particle_list)):
		var particle = particle_list[i]
		var speed_scale = speed_scale_list[i]
		particle.speed_scale = 0 if is_pause else speed_scale
