Skip to content

Commit 129b1cd

Browse files
Fixed issue where uGUI raycasting was compensating for Unity Bug. Unity now correctly calculates from the nearclip plane.
1 parent c06269b commit 129b1cd

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Assets/HoloToolkit/Input/Scripts/Gaze/GazeManager.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ private void RaycastUnityUI()
231231
// If we have a raycast result, check if we need to overwrite the 3D raycast info
232232
if (uiRaycastResult.gameObject != null)
233233
{
234-
// Add the near clip distance since this is where the raycast is from
235-
float uiRaycastDistance = uiRaycastResult.distance + Camera.main.nearClipPlane;
236-
237234
bool superseded3DObject = false;
238235
if (IsGazingAtObject)
239236
{
@@ -250,15 +247,15 @@ private void RaycastUnityUI()
250247
}
251248
else if (threeDLayerIndex == uiLayerIndex)
252249
{
253-
if (hitInfo.distance > uiRaycastDistance)
250+
if (hitInfo.distance > uiRaycastResult.distance)
254251
{
255252
superseded3DObject = true;
256253
}
257254
}
258255
}
259256
else
260257
{
261-
if (hitInfo.distance > uiRaycastDistance)
258+
if (hitInfo.distance > uiRaycastResult.distance)
262259
{
263260
superseded3DObject = true;
264261
}
@@ -269,10 +266,10 @@ private void RaycastUnityUI()
269266
if (!IsGazingAtObject || superseded3DObject)
270267
{
271268
IsGazingAtObject = true;
272-
Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(uiRaycastResult.screenPosition.x, uiRaycastResult.screenPosition.y, uiRaycastDistance));
273-
hitInfo = new RaycastHit()
269+
Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(uiRaycastResult.screenPosition.x, uiRaycastResult.screenPosition.y, uiRaycastResult.distance));
270+
hitInfo = new RaycastHit
274271
{
275-
distance = uiRaycastDistance,
272+
distance = uiRaycastResult.distance,
276273
normal = -Camera.main.transform.forward,
277274
point = worldPos
278275
};
@@ -313,9 +310,9 @@ private RaycastResult FindClosestRaycastHitInLayermasks(List<RaycastResult> cand
313310
}
314311
}
315312

316-
return minHit ?? new RaycastResult();
313+
return minHit ?? new RaycastResult();
317314
}
318-
315+
319316
/// <summary>
320317
/// Look through the layerMaskList and find the index in that list for which the supplied layer is part of
321318
/// </summary>

0 commit comments

Comments
 (0)