一、3D拾取技术 Ray.origin:射线起点 Ray.direction:射线的方向 创建一条射线:
Ray(origin;Vector3,direction:Vector3);
从原点发射一条射线:
Ray ray=new Ray(Vector.zero,transform.position);
RaycastHit hit;
Physics.Raycast(ray,out hit,100);
Debug.DrawLine(ray.origin,hit.point);
点击鼠标左键克隆游戏对象:
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Instantiate(cube,hit.point,Quaternion.identity);
}
}
Mathf.Infinity :无限 1 << LayerMask.NameToLayer(“cube”): 查找的是cube层
|