How to add custom script on Target Detected?

0 votes
asked Aug 12, 2017 by cloudapptimize (270 points)
Hello,

I am new to Easy AR.

I modified HelloArTarget image and model to use my own and it gets detected as expected.

Now I want to show some icons when target is detected. So I will have near to 20 targets and 20 corresponding image targets.

As soon as any of the image target gets detected, I want to show some buttons like Play audio etc to do some activity specific to the detected target.

I have created a empty game object and linked one new script with same.

So my question is

1. how can I dynamically control and add code in my custom script (not is standard) tp detect when there is a object in tracked state?

2. How to get info about the object in my custom script after it gets detected?

I can see standard code with provided code uses EasyAR namespace. Please help. Thanks

2 Answers

0 votes
answered Aug 13, 2017 by albert52 (31,850 points)

hi,

of course.You can refer to this script(https://www.easyar.com/doc/EasyAR%20SDK/Getting%20Started/2.0/Setting-up-EasyAR-Unity-SDK.html):

public class EasyImageTargetBehaviour : ImageTargetBehaviour
{
    protected override void Awake()
    {
        base.Awake();
        TargetFound += OnTargetFound;
        TargetLost += OnTargetLost;
        TargetLoad += OnTargetLoad;
        TargetUnload += OnTargetUnload;
    }

    void OnTargetFound(TargetAbstractBehaviour behaviour)
    {
        Debug.Log("Found: " + Target.Id);
    }

    void OnTargetLost(TargetAbstractBehaviour behaviour)
    {
        Debug.Log("Lost: " + Target.Id);
    }

    void OnTargetLoad(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
    {
        Debug.Log("Load target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
    }

    void OnTargetUnload(ImageTargetBaseBehaviour behaviour, ImageTrackerBaseBehaviour tracker, bool status)
    {
        Debug.Log("Unload target (" + status + "): " + Target.Id + " (" + Target.Name + ") " + " -> " + tracker);
    }
}
0 votes
answered Sep 7, 2017 by kenn (18,750 points)
Actually those are not standard code, those code in the sample are what you want. We have changed those missing leading namespaces and filenames in the upcoming 2.1 release to make a clear boundary.
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...