Files
sampleproj/Assets/lua/door.lua
Jan Racek fcb25a5388 lol
2026-03-29 18:40:52 +02:00

45 lines
1.4 KiB
Lua

-- ============================================================================
-- door.lua - Interactable door that opens/closes via animation
-- ============================================================================
-- Tests: onInteract, Animation.Play with onComplete, Animation.IsPlaying,
-- Interact.SetEnabled, self.position, self.rotation, Audio
local isOpen = false
function onCreate(self)
isOpen = false
Debug.Log("Door created at " .. self.position.x .. "," .. self.position.y .. "," .. self.position.z)
end
function onInteract(self)
if Animation.IsPlaying("door_open") or Animation.IsPlaying("door_close") then
return
end
if isOpen then
isOpen = false
Interact.SetEnabled(self, false)
Audio.Play("door_close", 100, 64)
setStatus("Closing door...")
Animation.Play("door_close", {
onComplete = function()
Interact.SetEnabled(self, true)
setStatus("Door closed.")
end
})
else
isOpen = true
Interact.SetEnabled(self, false)
Audio.Play("door_open", 100, 64)
setStatus("Opening door...")
Animation.Play("door_open", {
onComplete = function()
Interact.SetEnabled(self, true)
setStatus("Door opened!")
end
})
end
end