요약
메서드
GetCollection(class: string):Instances |
이벤트
ItemAdded(instance: Instance):RBXScriptSignal |
ItemRemoved(instance: Instance):RBXScriptSignal |
TagAdded(tag: string):RBXScriptSignal |
TagRemoved(tag: string):RBXScriptSignal |
상속된 멤버
API 참조
메서드
AddTag
GetCollection
GetInstanceAddedSignal
매개 변수
코드 샘플
컬렉션 서비스 사용한 치명적인 블록
local CollectionService = game:GetService("CollectionService")
local tag = "Deadly"
local function onDeadlyPartTouched(otherPart)
if not otherPart.Parent then
return
end
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- 태그가 제거될 때 연결을 끊을 수 있도록 연결을 저장합니다.
local connections = {}
local function onInstanceAdded(object)
-- 이 태그가 붙은 객체가 BasePart인지 확인합니다.
if object:IsA("BasePart") then
connections[object] = object.Touched:Connect(onDeadlyPartTouched)
end
end
local function onInstanceRemoved(object)
-- 이 객체에 저장된 연결이 있으면 연결을 끊습니다.
if connections[object] then
connections[object]:Disconnect()
connections[object] = nil
end
end
-- 이 태그가 객체에 적용될 때를 감지합니다.
CollectionService:GetInstanceAddedSignal(tag):Connect(onInstanceAdded)
CollectionService:GetInstanceRemovedSignal(tag):Connect(onInstanceRemoved)
-- 이미 태그가 있는 객체를 감지합니다.
for _, object in pairs(CollectionService:GetTagged(tag)) do
onInstanceAdded(object)
endGetInstanceRemovedSignal
매개 변수
코드 샘플
컬렉션 서비스 사용한 치명적인 블록
local CollectionService = game:GetService("CollectionService")
local tag = "Deadly"
local function onDeadlyPartTouched(otherPart)
if not otherPart.Parent then
return
end
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- 태그가 제거될 때 연결을 끊을 수 있도록 연결을 저장합니다.
local connections = {}
local function onInstanceAdded(object)
-- 이 태그가 붙은 객체가 BasePart인지 확인합니다.
if object:IsA("BasePart") then
connections[object] = object.Touched:Connect(onDeadlyPartTouched)
end
end
local function onInstanceRemoved(object)
-- 이 객체에 저장된 연결이 있으면 연결을 끊습니다.
if connections[object] then
connections[object]:Disconnect()
connections[object] = nil
end
end
-- 이 태그가 객체에 적용될 때를 감지합니다.
CollectionService:GetInstanceAddedSignal(tag):Connect(onInstanceAdded)
CollectionService:GetInstanceRemovedSignal(tag):Connect(onInstanceRemoved)
-- 이미 태그가 있는 객체를 감지합니다.
for _, object in pairs(CollectionService:GetTagged(tag)) do
onInstanceAdded(object)
endGetTagged
매개 변수
반환
Instances
코드 샘플
컬렉션 서비스 사용한 치명적인 블록
local CollectionService = game:GetService("CollectionService")
local tag = "Deadly"
local function onDeadlyPartTouched(otherPart)
if not otherPart.Parent then
return
end
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
-- 태그가 제거될 때 연결을 끊을 수 있도록 연결을 저장합니다.
local connections = {}
local function onInstanceAdded(object)
-- 이 태그가 붙은 객체가 BasePart인지 확인합니다.
if object:IsA("BasePart") then
connections[object] = object.Touched:Connect(onDeadlyPartTouched)
end
end
local function onInstanceRemoved(object)
-- 이 객체에 저장된 연결이 있으면 연결을 끊습니다.
if connections[object] then
connections[object]:Disconnect()
connections[object] = nil
end
end
-- 이 태그가 객체에 적용될 때를 감지합니다.
CollectionService:GetInstanceAddedSignal(tag):Connect(onInstanceAdded)
CollectionService:GetInstanceRemovedSignal(tag):Connect(onInstanceRemoved)
-- 이미 태그가 있는 객체를 감지합니다.
for _, object in pairs(CollectionService:GetTagged(tag)) do
onInstanceAdded(object)
endGetTags
매개 변수
반환
코드 샘플
태그와 CollectionService 사용하기
local CollectionService = game:GetService("CollectionService")
local Workspace = game:GetService("Workspace")
local object = Workspace.Part
-- 태그 추가하기
CollectionService:AddTag(object, "Deadly")
-- 태그 쿼리하기
if CollectionService:HasTag(object, "Deadly") then
print(object:GetFullName() .. "는 치명적입니다")
end
-- 객체의 태그 목록
local tags = CollectionService:GetTags(object)
print("객체 " .. object:GetFullName() .. "의 태그: " .. table.concat(tags, ", "))
-- 태그 제거하기
CollectionService:RemoveTag(object, "Deadly")HasTag
반환
코드 샘플
태그와 CollectionService 사용하기
local CollectionService = game:GetService("CollectionService")
local Workspace = game:GetService("Workspace")
local object = Workspace.Part
-- 태그 추가하기
CollectionService:AddTag(object, "Deadly")
-- 태그 쿼리하기
if CollectionService:HasTag(object, "Deadly") then
print(object:GetFullName() .. "는 치명적입니다")
end
-- 객체의 태그 목록
local tags = CollectionService:GetTags(object)
print("객체 " .. object:GetFullName() .. "의 태그: " .. table.concat(tags, ", "))
-- 태그 제거하기
CollectionService:RemoveTag(object, "Deadly")RemoveTag
반환
()
코드 샘플
태그와 CollectionService 사용하기
local CollectionService = game:GetService("CollectionService")
local Workspace = game:GetService("Workspace")
local object = Workspace.Part
-- 태그 추가하기
CollectionService:AddTag(object, "Deadly")
-- 태그 쿼리하기
if CollectionService:HasTag(object, "Deadly") then
print(object:GetFullName() .. "는 치명적입니다")
end
-- 객체의 태그 목록
local tags = CollectionService:GetTags(object)
print("객체 " .. object:GetFullName() .. "의 태그: " .. table.concat(tags, ", "))
-- 태그 제거하기
CollectionService:RemoveTag(object, "Deadly")이벤트
ItemAdded
ItemRemoved