Unity日记-移动UI
1.在需要给需要移动的UI添加一个Empty GameObject的父物体。
2.通过RectTransform找到Empty GameObject。
3.用Empty.anchredPosition来控制UI坐标。
4.以上为瞬间移动若是需要展现出移动过程可以用以下类似代码
public RectTransform mainmenu;//需要将父物体拖到这里
for (float i = 0; i < 100; i++) //i代表需要移动的次数
{
StartCoroutine(waitsecond(i));
}
IEnumerator waitsecond(float i)
{
yield return new WaitForSeconds(0f);
//bp为目标地点坐标
Vector2 bp = new Vector3(mainmenu.anchoredPosition.x + 1, mainmenu.anchoredPosition.y);//p.x+1则是改变的像素距离
mainmenu.anchoredPosition = bp;//对UI进行移动
}