第一,摄像机发射射线,脚本如下:
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
//print(hit.point);//射线与碰撞体的交点坐标
//Debug.Log(hit.collider.name);
Debug.DrawLine(ray.origin, hit.point, Color.red);
GameObject go = Instantiate(sphere);
go.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
Destroy(go, 0.02f);
}
网友评论