与最近物体碰撞取得位置:
private Vector3 GetMousePoint()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
if (isCollider)
{
return hit.point;
}
return Vector3.zero;
}
与指定层的物体碰撞:
bool isCollider =Physics.Raycast(ray, out hit, 1000, LayerMask.GetMask("your define"));
另外collider相当于游戏物体了
hit.collider.GetComponent<your script>();