UIDraggablePanel 移动滑动块到指定位置
-
获取需要移动的 UIDraggablePanel 的实例。
-
获取需要移动到的目标位置。
-
计算需要移动的距离。
-
调用 UIDraggablePanel 的 MoveRelative 方法,传入计算出的距离参数。
-
将需要移动的物体的位置设置为目标位置。
-
调用 UIDraggablePanel 的 RestrictWithinBounds 方法,使移动后的位置在 UIDraggablePanel 的边界内。
示例代码:
public class MovePanel : MonoBehaviour
{
public UIDraggablePanel draggablePanel;
public Vector3 targetPosition;
public void MoveToTargetPosition()
{
Vector3 distance = targetPosition - draggablePanel.transform.localPosition;
draggablePanel.MoveRelative(distance);
draggablePanel.transform.localPosition = targetPosition;
draggablePanel.RestrictWithinBounds(true);
}
}
``
原文地址: https://www.cveoy.top/t/topic/gAOn 著作权归作者所有。请勿转载和采集!