unity 在没有碰撞物的情况下,射线生成物体
2020-09-10 本文已影响0人
WOTTOW



public Camera mainCamrea;
public float h = 0;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Ray ray = mainCamrea.ScreenPointToRay(Input.mousePosition);
float dis = (h - ray.origin.y) / ray.direction.y;
Vector3 pos = ray.origin + ray.direction * dis;
Clone(pos);
}
}
private void Clone(Vector3 pos)
{
GameObject cl = GameObject.CreatePrimitive(PrimitiveType.Sphere);
cl.transform.position = pos;
}