Kanagalingam
Kanagalingam

Reputation: 2214

How to disappear multiple canvas on target lost in Unity Vuforia?

I know the below code disappears canvas on tracking lost in Vuforia. Under DefaultTrackableEvent.cs,

Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);

        // Disable canvas:
        foreach (Canvas component in canvasComponents)
        {
            component.enabled = false;
        }

Now i have 3 canvas and i want 2 canvas elements to disappear on target lost. The above is not working for this! Can you help me with a solution!

Upvotes: 0

Views: 641

Answers (2)

Kanagalingam
Kanagalingam

Reputation: 2214

I make it work by keeping both the canvas inside the parent GameObject and placing the parent GameObject inside ImageTarget in Hierarchy.

BTW, always make sure that the canvas to be hidden on TargetLost must be always inside ImageTarget in Hierarchy !

Upvotes: 0

Umair M
Umair M

Reputation: 10750

If you know which one of these you want to keep enabled, you can skip it by using if statement.

Canvas[] canvasComponents = GetComponentsInChildren<Canvas>(true);

// Disable canvas:
foreach (Canvas component in canvasComponents)
{
    if(component.gameObject.tag != "someTag")
        component.enabled = false;
}

now set tag of that specific canvas to someTag

Hope this helps

Upvotes: 0

Related Questions