GetAllChild
格式
GetAllChild()
- 函数
- 所属对象:RWObject
简介
返回一个数组,其中包含对象的所有直接子级,或每个父级Parent等于该对象的实例。可以使用数字或通用for循环迭代数组。
返回值
类型 | 描述 |
---|---|
table | 自身的所有子级对象 |
实例
返回一个包含所有直接子节点对象的数组。
local workSpace=GetService("WorkSpace") --获取工作区服务
local temp = RWObject:New("Part") --创建一个零件
local temp2 = RWObject:New("Folder")--创建一个文件夹
temp.Position = Vector3.New(3,3,3) --设置零件的坐标并锚定
temp.Anchored = true
temp.Parent = workSpace--将零件和文件夹的父级设置为WorkSpace
temp2.Parent = workSpace
for i = 1,4 do--用for循环克隆零件
temp1 = temp:Clone()
temp1.Name = tostring(i)--克隆零件用克隆次数命名
temp.Position = Vector3.New(3+i,3,3+i)--根据克隆次数设置零件坐标
temp1.Parent = temp2--克隆出的零件父级都为文件夹temp2
end
for _,Child in pairs(temp2:GetAllChild()) do--用pairs遍历temp2的GetAllChild()所有子级对象的表
Child.Color = Vector3.New(255,0,0)--将子级对象的颜色设置为红色
end
文档更新时间: 2020-07-11 17:46 作者:王辰剑