Search Unity

Unity 4.6 Canvas with Vuforia

Discussion in 'Scripting' started by Synapz, Nov 26, 2014.

  1. Synapz

    Synapz

    Joined:
    Oct 2, 2014
    Posts:
    16
    Hello,

    I didn't knew where to post this, so if this is the wrong place, i am sorry.
    im also posting this on vuforia forum but wanted to post it here as well for more answers.
    so if its wrong i am deeply sorry and it can be removed or placed somewhere where it belongs.
    anyway..

    i have a setup within unity with vuforia with the new 4.6 ui canvas.
    i have made a canvas with several buttons, all nice..
    then i have a movie run on the target from vuforia with universal video texture plugin.

    when all things are set up with camera and stuff, when i play the button. everything disappears like it should and when the camera sees the target then the movie is shown.
    but the canvas and its ui elements don't disappear.. so when i have multiple targets next to each other, all with there own ui. i see all the ui elements of all the targets flying there.
    i have set my canvas to world mode because it needs to be set around the movie.
    i also made all the items a child of the image target.

    can anyone help how to hide the canvas and only show it when the target is visible?
    is there some option i missed?

    thanks in advance.

    Nick.
     
  2. hacky97

    hacky97

    Joined:
    Feb 6, 2014
    Posts:
    6
    maybe a bit late, but to keep this thread complete for future reference:
    add the following to the TrackableEentHandler.cs -> OnTrackingFound() function:

    Code (CSharp):
    1.  
    2. Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
    3.  
    4.             // Enable canvas objects
    5.             foreach (Canvas component in canvasComponents)
    6.             {
    7.                 component.enabled = true;
    8.             }
    9.  
    and add the following to the TrackableEentHandler.cs -> OnTrackingLost() function:

    Code (CSharp):
    1.  
    2. Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);
    3.  
    4.             // Disable canvas objects
    5.             foreach (Canvas component in canvasComponents)
    6.             {
    7.                 component.enabled = false;
    8.             }
    9.  
    (The standard TrackableEventHandler.cs only enables renderers and colliders)
     
    fedemoglia likes this.
  3. fedemoglia

    fedemoglia

    Joined:
    Jul 12, 2016
    Posts:
    1
    @hacky97 it works! I'm using Unity 5.3.4f1. Thanks!
     
  4. hollym16

    hollym16

    Joined:
    Feb 21, 2013
    Posts:
    13
    @hacky97 I've tried using your script and it works great if you set the Canvas to world space and make it a child of the Image Target.
    Unfortunately I want to use it as Screen Space Overlay (so the buttons are fixed to the screen.) With this, I can't make it a Child of the Image Target without issues. I've tried making the Canvas[] a public variable and assigning it in the inspector but nothing happens.
    Any ideas on how I can get this working?