Unity3D鼠标拖拽物体贴地面移动代码
Ray clickRay;
RaycastHit clickPoint;
RaycastHit posPoint;
LayerMask mask=1<<8;
void Start () {
}
void Update(){
clickRay=Camera.main.ScreenPointToRay(Input.mousePosition);
}
void OnMouseDown()
{
if(Physics.Raycast (clickRay,out clickPoint))
{
OnMouseDrag();
}
}
void OnMouseDrag()
{
Physics.Raycast (clickRay ,out posPoint,Mathf.Infinity,mask.value);
Vector3 mouseMove=posPoint.point;
transform.position = (new Vector3 (mouseMove.x, transform.position.y, mouseMove.z));
return;
}
}
- 下一篇:Unity3D加载和内存管理机制
- 上一篇:unity3d 禁用脚本