Now I make a game that ball will merge to another ball.
like Ball2 collide with Ball2 will merge to Ball_4.
When the Ball2 make collide it will call code in Ball2 to merge and add Ball4 instance to spawner, But code in Ball2 call 2 times I want it to call just one time
here the Ball_2 code if you want, Thank you all :D
extends RigidBody2D
var merge = preload("res://Ball_res/Ball_4.res")
func _ready(): # release ball at mouse position
var mouse_position = get_global_mouse_position()
if(mouse_position[0] >= -470 and mouse_position[0] <= 470) and (mouse_position[1] >= -300 and mouse_position[1] <= -250) :
translate(Vector2(mouse_position[0],0))
pass
pass
func _on_Ball_2_body_entered(body): # merge ball
if "Ball_2" in body.name :
var ball_instance = merge.instance()
ball_instance.set_name("Ball_4(Clone)")
Global.merge_position = position
get_parent().add_child(ball_instance)
queue_free()
pass
pass