![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | turtilla955 |
im trying to make interactable objects display text based on what key should be used to interact with it. when i run the game it opens fine but when i look at one of the objects it crashes and gives me the error.
here are the scripts:
(interactable.gd)
class_name Interactable
extends StaticBody
export var prompt_message = "Interact"
export var prompt_action = "interact"
func get_prompt():
var key_name = ""
for action in InputMap.get_action_list(prompt_action):
if action is InputEventKey:
key_name = OS.get_scancode_string(action.scancode)
return prompt_message + "\n[" + key_name + "]"
(interactRay.gd)
extends RayCast
onready var prompt = $prompt
# Called when the node enters the scene tree for the first time.
func _ready():
add_exception(owner)
func _physics_process(delta):
prompt.text = ""
if is_colliding():
var detected = get_collider()
if detected is Interactable:
prompt.text = detected.get_prompt()