I'm using unity with C# in Visual Studio 2015 and whenever I use something like this:
if (!NavMesh.SamplePosition(position, out NavMeshHit hit, 1f, NavMesh.AllAreas)) { return; }
or this
if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }
I get a compile time error warning for RaycastHit hit
or NavMeshHit hit
and where ever hit
is used after that.
if I declare it as local variable the error goes away
NavMeshHit hit;
if (!NavMesh.SamplePosition(position, out hit, 1f, NavMesh.AllAreas)) { return; }
RaycastHit hit;
if (!Physics.Raycast(ray, out hit, Mathf.Infinity)) { return; }
or by pressing Ctrl + .
and then Esc
canceling it, the error goes away and even if it doesn't, it just compiles OK and goes into run-time with no problem.
is there a way to resolve this inside visual studio?