요약
코드 샘플
컬렉션 생명주기 및 이벤트
local CollectionService = game:GetService("CollectionService")
-- "MapleLeaf" 태그가 붙은 파트의 실시간 컬렉션으로, "MapleTree" 태그가 붙은 모델의 직접 자식입니다.
local mapleLeaves: Collection = CollectionService:CreateCollection("Model.MapleTree > Part.MapleLeaf")
local function sway(leaf: Part, deltaTime: number)
leaf.CFrame *= CFrame.fromEulerAnglesXYZ(0, math.rad(20) * deltaTime, 0)
end
local function fall(leaf: Part)
leaf.Anchored = false
end
-- OnAdded는 이미 일치하는 각 리프에 대해 한 번 발생한 후, 각 새로운 일치에 대해 발생합니다.
function mapleLeaves.OnAdded(leaf: Part)
leaf.Material = Enum.Material.Neon
end
-- OnRemoved는 리프가 일치하지 않을 때(태그가 제거되거나, 나무에서 재부모되거나, 파괴될 때) 발생합니다.
function mapleLeaves.OnRemoved(leaf: Part)
leaf.Material = Enum.Material.Plastic
end
-- RunService 콜백: 컬렉션의 각 리프에 대해 매 심장 박동마다 한 번 발생합니다.
function mapleLeaves.OnHeartbeat(leaf: Part, deltaTime: number)
sway(leaf, deltaTime)
end
-- 이벤트 콜백: 각 리프의 BasePart.Touched에 연결됩니다.
function mapleLeaves.OnTouched(leaf: Part, other: BasePart)
fall(leaf)
end
-- 속성 콜백: 리프의 색상이 변경될 때 발생합니다.
function mapleLeaves.OnPropertyChanged.Color(leaf: Part)
if leaf.Color == Color3.fromRGB(124, 92, 70) then
fall(leaf)
end
end
-- 현재 컬렉션에 있는 모든 리프를 초록색으로 설정합니다.
mapleLeaves:ForEach(function(leaf: Part)
leaf.Color = Color3.fromRGB(0, 255, 0)
end)API 참조
속성
메서드
Destroy
Collection:Destroy()