35 lines
804 B
Lua
35 lines
804 B
Lua
-- collectible.lua - Pickup item
|
|
-- Tests: onCreate, onDestroy, onEnable, onDisable, onCollideWithPlayer,
|
|
-- Entity.SetActive, Audio.Play, Persist, self.active, self.position
|
|
|
|
local collected = false
|
|
|
|
function onCreate(self)
|
|
collected = false
|
|
Debug.Log("Collectible created at "
|
|
.. self.position.x .. "," .. self.position.y .. "," .. self.position.z)
|
|
end
|
|
|
|
function onDestroy(self)
|
|
Debug.Log("Collectible destroyed")
|
|
end
|
|
|
|
function onEnable(self)
|
|
Debug.Log("Collectible enabled")
|
|
end
|
|
|
|
function onDisable(self)
|
|
Debug.Log("Collectible disabled")
|
|
end
|
|
|
|
function onCollideWithPlayer(self)
|
|
if collected then return end
|
|
collected = true
|
|
|
|
Audio.Play("collect", 127, 64)
|
|
Entity.SetActive(self, false)
|
|
|
|
addScore(100)
|
|
setStatus("Collected! +100 points")
|
|
end
|