I have a function for the player and extends on global script
func die():
var colider = get_collision()
var colider_name = get_collision_name()
var explosion = load("res://scenes/explosion.tscn").instance()
if colider_name == 'small_asteroid' or colider_name == 'middle_asteroid' or colider_name == 'big_asteroid':
asteroids.before_die(colider, colider_name)
explosion.position = global_position
get_parent().add_child(explosion)
queue_free()
and functions in the script global
func get_collision():
for i in get_slide_count():
var collision = get_slide_collision(i)
return collision.collider
func get_collision_name():
for i in get_slide_count():
var collision = get_slide_collision(i)
return collision.collider.name
if I add asteroids to the scene myself, the player's script will work, but if I add asteroids through the script, the player's script will not work. I noticed that the created asteroids have different names that I check in the player script. I tried to change their names by adding the asteroids themselves to the script
set_name(name_of_asteroid)
but it didn't work, can anyone please show me the code how this can be solved.