Open Faladr4do opened 6 months ago
implement this code
extends Node2D
var new_child_node : Node2D = preload("res://NewChildNode.tscn")
func _ready():
body_entered
_on_area_entered
$Area.connect("body_entered", self, "_on_area_entered")
func _on_area_entered(body):
if body.is_in_group("PlayerGroup"): # Replace the old child with the new one replace_child(new_child_node)
func replace_child(new_child: Node2D): var parent_node = self parent_node.replace_child($OldChildNode, new_child)
$OldChildNode.queue_free()
implement this code
extends Node2D
var new_child_node : Node2D = preload("res://NewChildNode.tscn")
func _ready():
Connect the area's
body_entered
signal to the_on_area_entered
methodfunc _on_area_entered(body):
Check if the entered body is in the player group
func replace_child(new_child: Node2D): var parent_node = self parent_node.replace_child($OldChildNode, new_child)
Optionally, you might want to free the old child node if you don't need it anymore