Вы должны объявить (Type variableName
) ранее в вашем условии, потому что они оцениваются слева направо, а затем, при первом условии (Physics.Linecast(head.position, vector, out hitInfo, sphereSensor.obstacleLayer)
), переменная hitInfo
еще не существует.
Измените свой код следующим образом:
// Notice this ---------------------------------v--------v
if (Physics.Linecast(head.position, vector, out RaycastHit hitInfo, sphereSensor.obstacleLayer)
&& Physics.Linecast(head.position, vector2, out hitInfo, sphereSensor.obstacleLayer)
&& Physics.Linecast(head.position, colliderTarget.bounds.center, out hitInfo, sphereSensor.obstacleLayer))
// Type was removed there -------------------------------------------^
Или объявите переменную перед:
RaycastHit hitInfo;
if (Physics.Linecast(head.position, vector, out hitInfo, sphereSensor.obstacleLayer)
&& Physics.Linecast(head.position, vector2, out hitInfo, sphereSensor.obstacleLayer)
&& Physics.Linecast(head.position, colliderTarget.bounds.center, out hitInfo, sphereSensor.obstacleLayer))