54 lines
1.2 KiB
GDScript
54 lines
1.2 KiB
GDScript
class_name NPC extends CharacterBody3D
|
|
|
|
enum InteractType {
|
|
NONE,
|
|
TEXTBOX,
|
|
CUTSCENE
|
|
}
|
|
|
|
# Movement speed in units per second
|
|
@export var gravity: float = 24.8
|
|
@export var interactType:InteractType = InteractType.NONE
|
|
@export_multiline var interactTexts:Array[String] = []
|
|
@export var cutscene:Cutscene = null
|
|
var nextTextIndex:int = 0
|
|
|
|
func _enter_tree() -> void:
|
|
$InteractableArea.interactEvent.connect(_on_interact)
|
|
|
|
func _exit_tree() -> void:
|
|
$InteractableArea.interactEvent.disconnect(_on_interact)
|
|
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|
|
|
|
func _physics_process(delta):
|
|
# Apply gravity if not on floor
|
|
if !is_on_floor():
|
|
velocity += PHYSICS.GRAVITY * delta
|
|
|
|
move_and_slide()
|
|
|
|
func _on_interact() -> void:
|
|
nextTextIndex = 0
|
|
match interactType:
|
|
InteractType.TEXTBOX:
|
|
if interactTexts.size() == 0:
|
|
return
|
|
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
|
UI.TEXTBOX.textboxClosing.connect(onTextboxClosing)
|
|
return
|
|
|
|
InteractType.CUTSCENE:
|
|
if cutscene:
|
|
cutscene.start()
|
|
return
|
|
_:
|
|
return
|
|
|
|
|
|
func onTextboxClosing() -> void:
|
|
nextTextIndex += 1
|
|
if nextTextIndex < interactTexts.size():
|
|
UI.TEXTBOX.setText(interactTexts[nextTextIndex])
|
|
else:
|
|
UI.TEXTBOX.textboxClosing.disconnect(onTextboxClosing)
|