Log in or register to post comments

Show Unity GUI only when certain objects are tracked

June 19, 2013 - 3:10am #1

I have a project at the moment using several image markers with animated models and static models. When I track an animated object, I would like some gui buttons to pop up with different functionality. Then when a non static object or no object is tracked the buttons will disappear. So far, The buttons are always visible. I have put a boolean in the DefaultTrackableEventHandler to let me know when I track an object or not but since all objects share this script, I can't modify it for each particular object that needs it.
What would be the best way to add custom functionality to each model?

Thanks

Show Unity GUI only when certain objects are tracked

August 25, 2017 - 5:05am #11

please provide me the C# code for tracking button on image target and the button is clickable

Show Unity GUI only when certain objects are tracked

August 2, 2013 - 1:31am #10

You will need to write some code and customise DefaultTrackableEventHandler.cs.

This script is applied to each Image Target.

Search the forums as I believe other developers have also sought how to do customised behaviour depending on the number of simultaneous trackables, and this is the starting point.

 

N

Show Unity GUI only when certain objects are tracked

August 1, 2013 - 4:17pm #9

Thank you NalinS
I got it working again thanks..
I just didnt understand it at first and I got confuse on the actual device and in the unity scene hehe.. :)

I manage to change the GUITexture to GUIText and now its working..

BUT my new problem if its possible,

how to show 2 Guitext at the same time when 2 markers were tracked at the same time

I tried 2 GUIText with different coordinates and 2 Markers.. when i track the 2 markers a the same time

the result is that the one GUItext just moving in random places and the other one cant be seen on the screen..

How will I achieve that
showing 2 Guitext at the same time when 2 markers were tracked at the same time or is it possible?

Show Unity GUI only when certain objects are tracked

August 1, 2013 - 2:21am #8

Guitext perhaps, as it is a Unity component which you will have more control over.

N

Show Unity GUI only when certain objects are tracked

July 31, 2013 - 9:59am #7

one last question.

What is the best way to pop up a text containing different name of the model and fades away on each target when its found?

should i use the Toast or just a guitext?

i check this but its seems its for eclipse not in unity??

https://developer.vuforia.com/forum/android/changing-action-after-recognized-tracker

 

thanks this is the last thing i need to figure out... more powers

Show Unity GUI only when certain objects are tracked

July 31, 2013 - 8:50am #6

ok - good to hear

Show Unity GUI only when certain objects are tracked

July 31, 2013 - 8:26am #5

thank you NalinS
I found the answers to my problems and I just use the raycast method..

Show Unity GUI only when certain objects are tracked

July 31, 2013 - 3:49am #4

I thought the instructions I wrote down were pretty clear....

1   Take the Image Targets app and add a GUITexture alongside the Teapot as a child of the Image Target.  

2   Then within the DefaultTrackableEventHandler.cs script (which is attached to the Image Target)  it is simply a case of switching it on in OnTrackingFound():

     (use the code below)

 

Can you see if you can get it working with one Image Target first?

Once you can do this it will give you confidence in how to tackle the same for more image targets.

 

N

 

 

Show Unity GUI only when certain objects are tracked

July 29, 2013 - 6:46pm #3

I 'll put my questions in numbers..

Im having a hard time figuring this out.

I want to have a guibutton in the same time with the model when the target is track...

My problem is that I have many image targets and model and having different contents

I used your codes but i dont know what is wrong...

1. Where should I put this  codes

In the model object or in the image marker??

 

  public GUITexture guiTextureButton;

void Update()

    {

        if ((guiTextureButton!= null) && Input.GetMouseButton(0) && guiTextureButton.HitTest(Input.mousePosition))

        {

            Debug.Log ("Button clicked");

        }

  
2. How can I make it work if I have many models and image targets..
3. Do i need to make individual GUITexture and attach the script for every model and image target?? and position it on the same coordinates with the image target or object model???

Thanks in advance..
By the way Im using Unity3d

Show Unity GUI only when certain objects are tracked

June 20, 2013 - 4:40am #2

Hi 8r3nd4n,

I would like some gui buttons to pop up with different functionality

This should be possible, though exactly how you want it to appear depends on the use case.  You could have 3D buttons rendered as cuboids, or you could have 2d GUITextures representing the buttons - the latter are a bit simpler to do, but there are one or two restrictions which you might be able to live with.

I was able to take the Image Targets app and add a GUITexture alongside the Teapot as a child of the Image Target.  Then within the DefaultTrackableEventHandler.cs script it is simply a case of switching it on in OnTrackingFound():

 

    GUITexture[] guiTextureComponents = GetComponentsInChildren<GUITexture>(true);

    foreach (GUITexture component in guiTextureComponents)

    {

            component.enabled = true;

    }

 

and off in OnTrackingLost():

 

    GUITexture[] guiTextureComponents = GetComponentsInChildren<GUITexture>(true);

    foreach (GUITexture component in guiTextureComponents)

    {

            component.enabled = false;

    }

 

Then, if you assign a public variable

 

    public GUITexture guiTextureButton;

 

and tie the actual GUITexture instance to it by dragging it to the placeholder in the Inspector, it will be possible to test for a click inside there:

 

    void Update()

    {

        if ((guiTextureButton!= null) && Input.GetMouseButton(0) && guiTextureButton.HitTest(Input.mousePosition))

        {

            Debug.Log ("Button clicked");

        }

    }

 

Note also that in this case I only added the GUITexture to one of the ImageTargets, which is the reason for the (guiTextureButton!= null) test, otherwise you get an exception on the two remaining Image Targets.

 

HTH

N

 

 

 

 

 

Log in or register to post comments