33 lines
850 B
GDScript
33 lines
850 B
GDScript
class_name EntityProximityArea extends Area3D
|
|
|
|
@export var entity:Entity
|
|
|
|
var _triggered:bool = false
|
|
var _chatbox:WorldChatBox = null
|
|
|
|
func _ready() -> void:
|
|
body_entered.connect(_onBodyEntered)
|
|
body_exited.connect(_onBodyExited)
|
|
|
|
func _onBodyEntered(body:Node3D) -> void:
|
|
if _triggered:
|
|
return
|
|
if !(body is Entity):
|
|
return
|
|
if (body as Entity).entityId != "player":
|
|
return
|
|
_triggered = true
|
|
assert(entity != null && entity.chatboxMessage != "")
|
|
if is_instance_valid(_chatbox) and _chatbox.visible:
|
|
_chatbox.resetTimer(entity.chatboxDuration)
|
|
else:
|
|
_chatbox = UI.spawnWorldChatBox(entity)
|
|
_chatbox.showTimed(entity.chatboxMessage, entity.chatboxDuration)
|
|
|
|
func _onBodyExited(body:Node3D) -> void:
|
|
if !(body is Entity):
|
|
return
|
|
if (body as Entity).entityId != "player":
|
|
return
|
|
_triggered = false
|