0

I have a question about the way how to show simple 2d image on top of detected marker. I have followed some tutorial to show 3d model and it works fine. there is no problem with 3d. The problem starts when I want to add normal 2d object->sprite . When I add simple sprite I can't add texture and when I insert UI image it's added together with canvas and it is not showed when target is detected. The original image on editor is placed then so far that it's difficult to find it. I would be grateful if somebody can highlight me the right direction.

  • I'm not very familiar with the Unity api, but take a look at the answer here, see if it helps: http://stackoverflow.com/questions/27953393/unity3d-with-vuforia-showing-2d-image-when-targed-is-detected – yakobom Feb 13 '17 at 04:56

1 Answers1

0

Under your ImageTargetyou need to have something like Trackable Event Handler script. For default it is DefaultTrackableEventHandler.

You can find there two methods: OnTrackingFound() & OnTrackingLost(). As tou can see those methods are enabling or disabling Colliders and Renderes, so there is no problem with showing 3D models, when target is detected. For showing 2D objects like Canvas or Sprite you need to modify those methods and and few lines.

For example:

 private void OnTrackingFound() {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
        Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
        Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);

        foreach (Canvas component in canvasComponents) {
            component.enabled = true;
        }

        // Enable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents) {
            component.enabled = true;
        }

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }

It helps in my case.