lul
This commit is contained in:
41
Assets/lua/switch.lua
Normal file
41
Assets/lua/switch.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- ============================================================================
|
||||
-- switch.lua - Toggle switch that activates/deactivates a target object
|
||||
-- ============================================================================
|
||||
-- Tests: onInteract, Entity.Find, Entity.IsActive, Entity.SetActive,
|
||||
-- Audio, self properties
|
||||
|
||||
local target = nil
|
||||
local switchOn = false
|
||||
|
||||
function onCreate(self)
|
||||
switchOn = false
|
||||
-- Find the object this switch controls (named "SwitchTarget")
|
||||
target = Entity.Find("SwitchTarget")
|
||||
if target then
|
||||
Entity.SetActive(target, false)
|
||||
Debug.Log("Switch: found target, initially off")
|
||||
else
|
||||
Debug.Log("Switch: WARNING - SwitchTarget not found!")
|
||||
end
|
||||
end
|
||||
|
||||
function onInteract(self)
|
||||
switchOn = not switchOn
|
||||
|
||||
if target then
|
||||
Entity.SetActive(target, switchOn)
|
||||
end
|
||||
|
||||
if switchOn then
|
||||
Audio.Play("switch_on", 100, 64)
|
||||
setStatus("Switch ON")
|
||||
else
|
||||
Audio.Play("switch_off", 100, 64)
|
||||
setStatus("Switch OFF")
|
||||
end
|
||||
|
||||
-- Test Entity queries
|
||||
local count = Entity.GetCount()
|
||||
Debug.Log("Switch toggled. Total entities: " .. count)
|
||||
Debug.Log("Target active: " .. tostring(Entity.IsActive(target)))
|
||||
end
|
||||
Reference in New Issue
Block a user