对象移动以及在 UNity3d 编辑器中

Object movement as well as in the UNity3d editor

也许你有一个移动对象的脚本,就像在编辑器UNity3d或商店中一样,其他人可以看到吗?付费或免费。例如,我单击了一个对象/选择了一个立方体,然后出现了箭头,然后我拉动了这些箭头,或者类似的东西?谢谢!

我找到了一个完全满足我需求的小脚本

    public class ClickAndDrop : MonoBehaviour
{

  private Vector3 screenPoint;
  private Vector3 offset;

  void OnMouseDown()
  {
    screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
    offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint
    (new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
  }

  void OnMouseDrag()
  {
    Vector3 cursorScreenPoint =
      new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
    Vector3 cursorPosition
      = Camera.main.ScreenToWorldPoint(cursorScreenPoint) + offset;
    transform.position
      = cursorPosition;
  }

}