Files
WickedEngine/Content/scripts/instantiate.lua
T
2024-05-09 12:06:12 +02:00

32 lines
896 B
Lua

-- This script demonstrates spawning multiple objects from one source scene
killProcesses() -- stops all running lua coroutine processes
backlog_post("---> START SCRIPT: instantiate.lua")
scene = GetScene()
scene.Clear()
local prefab = Scene()
LoadModel(prefab, script_dir() .. "../models/hologram_test.wiscene")
-- Instantiate first object
scene.Instantiate(prefab)
runProcess(function()
while true do
-- Instantiate more objects whenever the user presses space
if input.Press(KEYBOARD_BUTTON_SPACE) then
-- passing true as second parameter attaches all entities to a common root
local root_entity = scene.Instantiate(prefab, true)
local transform_component = scene.Component_GetTransform(root_entity)
transform_component.Translate(Vector(math.random() * 10 - 5, 0, math.random() * 10 - 5))
end
update()
end
end)
backlog_post("---> END SCRIPT: instantiate.lua")