我试图用Physics.Raycast的方法,但我得到的错误说:

  

关于 'UnityEngine.Physics.Raycast(UnityEngine.Vector3,UnityEngine.Vector3,浮动,INT)' 最好的重载的方法匹配具有一些无效参数。

这很奇怪,因为这两个itellisense和文档告诉我,这是允许的:

RaycastHit hit = new RaycastHit();
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
    print(hit.point.ToString());
    selection.transform.Translate(hit.point - selection.transform.position);
}

任何想法?

有帮助吗?

解决方案

我想你需要“砸”在Physics.Raycast(射线,命中)之前出的关键字。

RaycastHit hit = new RaycastHit();
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) {
    print(hit.point.ToString());
    selection.transform.Translate(hit.point - selection.transform.position);
}

其他提示

在C#,我们必须在变量命中之前使用的前体输出参数 为了得到该函数到数据分配给它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top