通过anchorMin和anchorMax来控制位置。
范围是0-1,x轴0是最左边,1是最右边。y轴0是最下面,1是最上面。是一个通过位置百分比的比例来算位置的。和各个设备的分辨率无关。
代码实现:
gameObject1.GetComponent<RectTransform>().anchorMin = new Vector2(0.5f, 0.2f);
gameObject1.GetComponent<RectTransform>().anchorMax = new Vector2(0.5f, 0.2f);
gameObject2.GetComponent<RectTransform>().anchorMin = new Vector2(0.5f, 0.4f);
gameObject2.GetComponent<RectTransform>().anchorMax = new Vector2(0.5f, 0.4f);
gameObject3.GetComponent<RectTransform>().anchorMin = new Vector2(0.5f, 0.6f);
gameObject3.GetComponent<RectTransform>().anchorMax = new Vector2(0.5f, 0.6f);