Search Unity

Question detecting multiple images using image tracking.

Discussion in 'AR' started by not_DiSE, Oct 24, 2021.

  1. not_DiSE

    not_DiSE

    Joined:
    Feb 18, 2019
    Posts:
    17
    Hi, is there a way to detect the tracked image the same way as the first time seeing it, I am trying to make it work the way, you scan the first tracked image it shows the name of the tracked image, when it gets off screen it hides the text, when you get it on screen it shows it again (this part works like a charm) BUT, when switching the images it works only if you show it an image it havent seen already. So if first you show it image 1 then image 2 it works but if you show it image 1 after that it doesnt detect it. I need help with this. this is the code:
    Code (CSharp):
    1. ARTrackedImageManager _arTrackedImageManager;
    2.     [SerializeField] Text text;
    3.  
    4.     private void Awake()
    5.     {
    6.         _arTrackedImageManager = FindObjectOfType<ARTrackedImageManager>();
    7.     }
    8.  
    9.     public void OnEnable()
    10.     {
    11.         _arTrackedImageManager.trackedImagesChanged += OnChanged;
    12.     }
    13.  
    14.     public void OnDisable()
    15.     {
    16.         _arTrackedImageManager.trackedImagesChanged -= OnChanged;
    17.     }
    18.    
    19.     public void OnChanged(ARTrackedImagesChangedEventArgs args)
    20.     {
    21.  
    22.         foreach (var trackedImage in args.updated)
    23.         {
    24.             if (trackedImage.trackingState != TrackingState.Limited && trackedImage.trackingState != TrackingState.None)
    25.             {
    26.                 text.text = (trackedImage.referenceImage.name);
    27.  
    28.             } else
    29.             {
    30.                 text.text = ("");
    31.             }
    32.  
    33.  
    34.         }