36 lines
904 B
GDScript
36 lines
904 B
GDScript
extends Area
|
|
|
|
export var on_interact_func = ""
|
|
export var on_enter_func = ""
|
|
export var on_leave_func = ""
|
|
export var call_string = ""
|
|
|
|
var cursor_is_touching = false
|
|
|
|
func _ready():
|
|
var _err = GlobalCursorState.connect("cursor_interact", self, "check_interact")
|
|
|
|
func call_with_value(func_name: String):
|
|
if call_string:
|
|
GlobalCursorState.call(func_name, call_string)
|
|
else:
|
|
GlobalCursorState.call(func_name)
|
|
|
|
func check_interact():
|
|
if cursor_is_touching and on_interact_func:
|
|
call_with_value(on_interact_func)
|
|
|
|
func _on_CursorInteractArea_body_entered(body):
|
|
if not GlobalCursorState.is_cursor_collision(body):
|
|
return
|
|
cursor_is_touching = true
|
|
if on_enter_func:
|
|
call_with_value(on_enter_func)
|
|
|
|
func _on_CursorInteractArea_body_exited(body):
|
|
if not GlobalCursorState.is_cursor_collision(body):
|
|
return
|
|
cursor_is_touching = false
|
|
if on_leave_func:
|
|
call_with_value(on_leave_func)
|