父子关系
//父对象
transform.parent
//设置父对象
transform.SetParent(父对象,是否保留世界坐标信息)
//断绝所有子对象关系
transform.DetachChildren()
//获取子对象
//按名字查找,可以找到失活对象,GameObject相关查找不行
//不能找子对象的子对象
transform.find("子对象名");
//遍历子对象
//子对象数量
transform.childCount
//通过索引号得到对应子对象
transform.GetChild(索引号)
//transform扩展函数,可以按名字找到子对象的子对象
public static Transform FindDeep(this Transform father, string name)
{
Transform target = null ;
target = father.Find(name);
if (target != null)
return target;
for(int i = 0; i < father.childCount; i++)
{
target = father.GetChild(i).FindDeep(name);
if (target != null)
return target;
}
return target;
}