Log in or register to post comments

UI Canvas Wont Disappear

January 26, 2016 - 6:00pm #1

Hello, im having a problem with my project.

When i run my application on mobile android,  the UI Canvas ( button, image) wont dissaper even after i move the camera from the ImageTarget. I know that i should edit something in the DefaultTrackableEventHandler.cs ( like the problem that i had with Unity terrain before), but im more into designing rather than coding. I hope you guys can help me with my problem.

 

 

UI Canvas Wont Disappear

January 21, 2018 - 7:16am #5

Kudos to you bro! ☺

UI Canvas Wont Disappear

July 26, 2017 - 1:21am #4

This was very useful, thanks!

UI Canvas Wont Disappear

March 6, 2017 - 12:12am #3

Thank you so much!! <3

UI Canvas Wont Disappear

January 29, 2016 - 4:27am #2

Hello

Since no one reply my question and i already have a solution for this (after extensive searching for the answer on Unity and Vuforia for several days). I want to post the solution.

If you want canvas and  terrain to dissapear after your camera not pointing at your image target, then you can follow this method.

1. Attach DefaultTrackableEventHandler.cs file to your ImageTarget

2. Open the script

3. Scroll until you find private void OnTrackingFound()

4. Input this code (under Collider[] line)

For Terrain

Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
 
foreach (Terrain component in terrainComponents)
{
component.enabled = true;
}
 

For Canvas

Canvas[] canvasObjects = GetComponentsInChildren<Canvas>();

foreach(Canvas canvas in canvasObjects)
{
canvas.enabled = true;
}

6. Then Scroll to private void OnTrackingLost()

For Terrain

Terrain[] terrainComponents = GetComponentsInChildren<Terrain>();
 
foreach (Terrain component in terrainComponents)
{
component.enabled = false;
}
 

For Canvas

Canvas[] canvasObjects = GetComponentsInChildren<Canvas>();

foreach(Canvas canvas in canvasObjects)
{
canvas.enabled = false;
}
7. If you have multiple Canvas that you use for your project, you can create empty Gameobject and rename it to parentObject or whatever you want, then put your canvas (that you want to hide after tracking lost)  under it as a child. Open your DefaultTrackableEventHandler.cs
 
8. Create public GameObject parentObject; above private void OnTrackingFound()
 
9. Then input this code under private void OnTrackingFound()
 
Canvas[] canvasObjects = parentObject.GetComponentsInChildren<Canvas>();
 
foreach(Canvas canvas in canvasObjects)
{
canvas.enabled = true;
 
 
10. Then go to private void OnTrackingLost()
 
Canvas[] canvasObjects = parentObject.GetComponentsInChildren<Canvas>();
 
foreach(Canvas canvas in canvasObjects)
{
canvas.enabled = false
 
I hope this can help other noobie coder like me. Thank you very much. If you have any question i will try to answer (with my limited knowledge) :D and I know my english sux :P
Log in or register to post comments