我创建一个emtpy游戏对象并附加.cs文件。我尝试在鼠标点击位置加载预制(.obj文件)。我的代码是:
Ray ray;
RaycastHit hit;
public GameObject prefab;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ray=Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
GameObject obj = Instantiate(prefab, new Vector3(hit.point.x, hit.point.y, hit.point.z), Quaternion.identity) as GameObject;
}
else
{
Debug.Log("Physics.Raycast returns false");
}
}
Raycast每次都会返回false。