Faladr4do / Project-Kandy

Jogo para PAP
1 stars 0 forks source link

New Level Changer #19

Open Faladr4do opened 6 months ago

Faladr4do commented 6 months ago

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 method

$Area.connect("body_entered", self, "_on_area_entered")

func _on_area_entered(body):

Check if the entered body is in the player group

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)

Optionally, you might want to free the old child node if you don't need it anymore

$OldChildNode.queue_free()