Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ARFoundation : Trouble ignoring touch events when over UI...

Discussion in 'AR' started by getoffworld, Jun 3, 2019.

  1. getoffworld

    getoffworld

    Joined:
    Feb 18, 2012
    Posts:
    9
    Where in the world should I place:

    && !EventSystem.current.IsPointerOverGameObject())

    in a script like "MakeAppearOnPlane.cs" so that when a user taps a UI element the placed object doesn't move all over the place? Following old ARKit tutorials (along with my seemingly total lack of C understanding) just results in error after error or simply no results.

    Any guidance or code snippets would be greatly appreciated. My attempt below clears the error but it certainly fails to produce the desired results


    void Update()
    {
    if (Input.touchCount == 0 || m_Content == null)
    return;

    var touch = Input.GetTouch(0);

    if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon) && !EventSystem.current.IsPointerOverGameObject())
    {
    // Raycast hits are sorted by distance, so the first one
    // will be the closest hit.
    var hitPose = s_Hits[0].pose;

    // This does not move the content; instead, it moves and orients the ARSessionOrigin
    // such that the content appears to be at the raycast hit position.
    m_SessionOrigin.MakeContentAppearAt(content, hitPose.position, m_Rotation);
    GetComponent<ARPlaneManager>().enabled = false;
    }
    }
     
  2. getoffworld

    getoffworld

    Joined:
    Feb 18, 2012
    Posts:
    9