【发布时间】:2017-02-26 01:31:20
【问题描述】:
将孩子的位置设置为父位置时遇到问题。
截图下方:
我的脚本:
RightNext.transform.GetChild (0).gameObject.transform.SetParent (TemporaryPage.transform,false); // TemporaryPage = Cherry Cake
RightNext.transform.GetChild (0).GetComponent<RectTransform> ().localScale = new Vector3 (1, 1, 1);
RightNext.transform.GetChild (0).gameObject.transform.parent = RightNext.transform;
RightNext.transform.GetChild (0).transform.position = RightNext.transform.position;
我把它放在更新中以确保位置没有改变。
为什么我的子位置不在内部并且与父位置相同,即使我已将其设置为与父位置相同的位置?
谢谢
丹尼斯
【问题讨论】:
-
你的子对象Position是否设置为0?
-
No.. 当它设置为 0 时我在使用什么? .Localposition 还是 .position ?
-
子游戏对象的变换组件上
-
你必须使用 RectTransform。因为它们是 ui 对象。
-
@NahuelIanni 我设置了位置(0,0,0)位置被移动,但移动到屏幕的中心而不是父对象的中心。 EmreE,我已经给子组件设置了RectTransform。