也许你有一个移动对象的脚本,就像在编辑器 UNity3d 中或在商店中一样,其他人可以看到吗?付费或免费。例如,我点击了一个对象/选择了一个立方体,然后出现了箭头,对于这些箭头我拉,或者类似的东西?谢谢 !
问问题
39 次
1 回答
0
我找到了一个完全满足我需求的小脚本
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;
}
}
于 2017-08-16T10:10:48.420 回答