Files
sampleproj/Assets/lua/npc.lua
Jan Racek 2cd9af28f1 eh fixes
2026-03-29 16:13:59 +02:00

48 lines
1.3 KiB
Lua

-- ============================================================================
-- npc.lua - NPC with multi-line dialogue
-- ============================================================================
-- Tests: onInteract, onButtonPress, Controls, UI text,
-- scene-level dialogue system, Input constants, Interact API
local talked = false
function onCreate(self)
talked = false
end
function onInteract(self)
if isInDialogue() then return end
-- Disable interaction while dialogue is open so the prompt hides
Interact.SetEnabled(self, false)
if not talked then
talked = true
startDialogue({
"Hello, traveler!",
"Welcome to the test scene.",
"There are collectibles, a door,",
"triggers, and a portal here.",
"Press CROSS to advance dialogue.",
"Good luck exploring!"
})
else
startDialogue({
"You again?",
"Go find the collectibles!",
"There should be three of them."
})
end
end
function onButtonPress(self, button)
if not isInDialogue() then return end
if button == Input.CROSS then
advanceDialogue()
-- Re-enable interaction when dialogue ends
if not isInDialogue() then
Interact.SetEnabled(self, true)
end
end
end