Question by
unity_7xSMfkBAg1Hzug · Nov 11, 2019 at 03:00 PM ·
uiraycastblock
AR Foundation ARRaycastmanager ray passing through UI,AR Foundation - ARRaycastmanager ray passing through UI
hi there, i m working with ARFoundation, the ray is passing through UI. ray is not blocking even after checking the eventsystem condition
int id = touch.fingerId; if (!EventSystem.current.IsPointerOverGameObject(id)),hi there i m not able to block ray from ARRaycastmanager, i checking finger toch
int id = touch.fingerId; if (!EventSystem.current.IsPointerOverGameObject(id))
Comment
Answer by Markus_T · Feb 17, 2020 at 02:28 PM
Test your touch input first with this code. If it returns true, then your touch was not over a UI element and you can use the touched position for whatever you like.
/// <summary>
/// Get the on-screen position of the users touch input
/// but ignore touches on UI elements
/// </summary>
/// <param name="_touchedPos"></param>
/// <returns>True if screen is touched</returns>
bool GetTouchPosition(out Vector2 _touchedPos)
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
_touchedPos = Input.GetTouch(0).position;
return true;
}
}
_touchedPos = default;
return false;
}