Search Unity

How to disable plane detection after the plane reaches a certain size

Discussion in 'AR' started by leafava, Mar 29, 2020.

  1. leafava

    leafava

    Joined:
    Mar 29, 2020
    Posts:
    2
    Hello, I'm trying to disable the ARPlaneManger after it has detected planes up to a certain size. However, when I run the code below, the plane manager continues to detect planes past the size of the area I have indicated. Does anyone know how this can be done? Below is my current code.

    Code (CSharp):
    1. private ARPlaneManager planeManager;
    2. private ARPlane plane;
    3.  
    4. void Awake()
    5. {
    6.     planeManager = GetComponent<ARPlaneManager>();
    7.     plane = GetComponent<ARPlane>();
    8. }
    9.  
    10. void OnEnable()
    11. {
    12.     plane.boundaryChanged += OnPlaneBoundaryChanged;
    13. }
    14.  
    15. void OnDisable()
    16. {
    17.     plane.boundaryChanged -= OnPlaneBoundaryChanged;
    18. }
    19.  
    20. void OnPlaneBoundaryChanged(ARPlaneBoundaryChangedEventArgs args)
    21. {
    22.     float planeArea = plane.size.x * plane.size.y;
    23.  
    24.     Debug.Log("Current plane area: " + planeArea);
    25.  
    26.     if (planeArea > 2.5f)
    27.     {
    28.         planeManager.enabled = false;
    29.  
    30.         Debug.Log("Plane manager is " + planeManager.enabled);
    31.     }
    32. }