Hello, everyone.
Faced with an issue that I cannot figure out for quite a long time.
I try to show a menu with some choices after the player hits the interact action near some specific object. Technically, the player model has a raycast2d and a function that detects a situation when the player hits an interact button near object, that has method called "on_interact".
I just completely don't understand how can I call an a UI and "deliver" it a control. It seems that I should create a condition in UI's unhandledinput that checks interact action and that the player stands near interactable object but I don't know how it can be implemented. Moreover, I am not sure the this way is a correct at all.
Unfortunately, most of what I've found either tells about interactions inside UI only or tells too superficially.
Here is some code for context. Here is a Player code of an interaction
func _process(delta):
if Input.is_action_just_pressed("interact"):
try_interact()
func try_interact ():
rayCast.cast_to = facingDir * interactDist
if rayCast.is_colliding():
if rayCast.get_collider().has_method("on_interact"):
rayCast.get_collider().on_interact(self)
On the other hand, a PopUp menu has a code like so
func _unhandled_input(event):
if not visible:
#if Input.is_action_just_pressed("interact"):
# Pause game
already_paused = get_tree().paused
get_tree().paused = true
# Reset the popup
selected_menu = 0
change_menu_color()
# Show popup
#player.set_process_input(false)
popup()
else:
if Input.is_action_just_pressed("ui_down"):
selected_menu = (selected_menu + 1) % 3;
change_menu_color()
elif Input.is_action_just_pressed("ui_up"):
if selected_menu > 0:
selected_menu = selected_menu - 1
else:
selected_menu = 2
change_menu_color()
elif Input.is_action_just_pressed("attack"):
match selected_menu:
# the code of processing the input