Log in or register to post comments

ITrackableEventHandler only triggers on 1 image, not any/all image targets.

March 9, 2017 - 7:56am #1

I am having issues with multi-image tracking and implementing the ITrackableBehaviour.

Here is the expected story: As a user, I want to view a sprite on my camera (think of it as like a crosshairs target) and when I scan any image target, this sprite will fade away on any image recognition and have the sprite fade back in when the image is gone.

I've applied the following script to the target (essentially a sprite image).

The issue is, the fade out of the sprite only occurs when scanning one particular scanned images, versus on 'any' of the scanned images.

 

I've posted the code here:

using UnityEngine;

using System.Collections;

using Vuforia;



public class Circles: MonoBehaviour, ITrackableEventHandler

{

     private float startTime;

     public GameObject circleOne;

     private TrackableBehaviour mTrackableBehaviour;



     void Start() {

         isFadeIn = false;

         isFadeOut = false;

         mTrackableBehaviour = GetComponent<TrackableBehaviour>();

         if (mTrackableBehaviour) mTrackableBehaviour.RegisterTrackableEventHandler(this);

     }



     public void OnTrackableStateChanged(

         TrackableBehaviour.Status previousStatus,

         TrackableBehaviour.Status newStatus)

     {

         if (newStatus == TrackableBehaviour.Status.DETECTED ||

             newStatus == TrackableBehaviour.Status.TRACKED ||

             newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

         {

             // Fade out circles when found

             this.fadeOut();

         }

         else

         {

             // Fade in circles when lost

             this.fadeIn();

         }

     }



     public void Update() {

         if (isFadeOut) {

                 ...

         } else if (isFadeIn) {

             ...

         }

     }



     private void fadeOut(){

         startTime = Time.time;

         isFadeOut = true;

         isFadeIn = false;

     }



     private void fadeIn(){

         startTime = Time.time;

         isFadeIn = true;

         isFadeOut = false;

     }

}

Log in or register to post comments