You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So for our project, since our camera is using perspective projection, the funciton
camera.WorldToScreenPoint() is not reliable when converting from world position to screen point, therefore the UnmaskRaycastFilter's function IsRaycastLocationValid() is always returning false no matter what.
However I have found a solution for this: instead of using camera.WorldToScreenPoint(), unity has a build in function RectTransformUtility.RectangleContainsScreenPoint() to check whether a screen point is inside the rect transform. So maybe this is better? At least it worked for me 😄
Here is the modified version of IsRaycastLocationValid() function:
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
// Skip if deactived.
if (!isActiveAndEnabled || !m_TargetUnmask || !m_TargetUnmask.isActiveAndEnabled){
return true;
}
// check inside
return !RectTransformUtility.RectangleContainsScreenPoint((m_TargetUnmask.transform as RectTransform), sp);
}
The text was updated successfully, but these errors were encountered:
UnmaskRaycastFilter is not reliable?
So for our project, since our camera is using perspective projection, the funciton
camera.WorldToScreenPoint()
is not reliable when converting from world position to screen point, therefore the UnmaskRaycastFilter's functionIsRaycastLocationValid()
is always returning false no matter what.However I have found a solution for this: instead of using
camera.WorldToScreenPoint()
, unity has a build in functionRectTransformUtility.RectangleContainsScreenPoint()
to check whether a screen point is inside the rect transform. So maybe this is better? At least it worked for me 😄Here is the modified version of
IsRaycastLocationValid()
function:The text was updated successfully, but these errors were encountered: