在普通gameObj下父子关系使用
son.transform.parent = father.transform;
在gui下,transform是RectTransfrom类型,直接使用上述代码会暴warning:
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent(Transform)
使用下面代码来处理:
son.transform.SetParent (father.transform);
参考:
unity transform.parent和SetParent效率差了几万倍? https://blog.csdn.net/fdyshlk/article/details/78670321