概要
範例程式碼
選擇
-- 獲取選擇的對象
local Selection = game:GetService("Selection")
-- 對每個對象進行迴圈
for _, object in pairs(Selection:Get())
do
-- 檢查對象是否為 BasePart
if object:IsA("BasePart") then
-- 旋轉對象
object.CFrame = object.CFrame *
CFrame.Angles(0, math.pi / 2, 0)
end
endAPI 參考
屬性
方法
Add
Selection:Add(instancesToAdd:Instances):()
參數
instancesToAdd:Instances |
返回
()
Get
Selection:Get():Instances
返回
Instances
範例程式碼
選擇
-- 獲取選擇的對象
local Selection = game:GetService("Selection")
-- 對每個對象進行迴圈
for _, object in pairs(Selection:Get())
do
-- 檢查對象是否為 BasePart
if object:IsA("BasePart") then
-- 旋轉對象
object.CFrame = object.CFrame *
CFrame.Angles(0, math.pi / 2, 0)
end
end選取.選取已變更
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("選取包含 " .. #selection:Get() .. " 項目.")
end)Remove
Selection:Remove(instancesToRemove:Instances):()
參數
instancesToRemove:Instances |
返回
()
Set
Selection:Set(selection:Instances):()
參數
selection:Instances |
返回
()
範例程式碼
選擇集
local Selection = game:GetService("Selection")
local newSelection = {}
for _, object in pairs(workspace:GetDescendants()) do
if object:IsA("BasePart") and object.BrickColor == BrickColor.new("Bright red") then
-- 將物件插入新的選擇中
table.insert(newSelection, object)
end
end
-- 設定新的選擇
Selection:Set(newSelection)活動
SelectionChanged
範例程式碼
選取.選取已變更
local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
print("選取包含 " .. #selection:Get() .. " 項目.")
end)