Hey, I am trying to make a Label appear whenever the player enters an Area2D. I want my Label to be hidden from the beginning and only show when the player is in the area. My issue is that the text is there before the player enters it. When the player enters the area and then leaves, the text disappears as well. Can someone help me out with this?
Hey, your reply helped me out! I didn’t exactly follow your instructions, but I managed to find a way to solve it that uses the same logic!
Code
extends Area2D
var entered = false
@onready var enterdungeontext = $enterdungeonlabel
@onready var player = $"../player" # made a variable that references to the player
func _ready():
enterdungeontext.visible = false
func _on_body_entered(body):
if body == player: # this checks if it's the player entering the Area2D
enterdungeontext.visible = true
entered = true
func _on_body_exited(_body):
enterdungeontext.visible = false
entered = false
func _physics_process(_delta):
if entered == true:
if Input.is_action_just_pressed("switch-maps"):
get_tree().change_scene_to_file("res://scenes/tutorial_dungeon.tscn")