I'm trying to use the Physics.Raycast
method, but I get 开发者_开发技巧errors saying:
The best overloaded method match for 'UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, float, int)' has some invalid arguments.
It's strange because both itellisense and the documentation tell me that this is permitted:
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);
}
Any idea?
I think you need the out keyword before "hit" in Physics.Raycast(ray, hit).
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);
}
In C# we must use a precursor out parameter before the variable hit in order to get the function to assign data to it.
精彩评论