Godot Version
4.x
Question
Ive set up a script where if my player character has entered this area2d and a button has been pressed, a textbox would appear, and on the subsequent click, the textbox would hide. Am i doing something wrong?
extends CanvasLayer
@onready var textbox_container = $TextboxContainer
@onready var start = $TextboxContainer/MarginContainer/HBoxContainer/Start
@onready var text = $TextboxContainer/MarginContainer/HBoxContainer/Text
@onready var end = $TextboxContainer/MarginContainer/HBoxContainer/End
@onready var charname = $TextboxContainer/MarginContainer/HBoxContainer/Name
@onready var animation_player = $"../AnimationPlayer"
@onready var state
func Textbox(currentname,Talktext):
charname.text = str(currentname)
text.text = str(Talktext)
func show_textbox():
animation_player.play("textbox_open")
func hide_textbox():
animation_player.play_backwards("textbox_open")
func _ready():
state = 0
visible = false
func _on_area_entered(body):
if Input.is_action_pressed("Confirm") and state == 0 and body == $"../../..":
visible = true
Textbox("jane doe","hi")
state = 1
elif Input.is_action_pressed("Confirm") and state == 1:
visible = false