In the DefaultTrackableEventHandler.cs
script (attached to every ImageTarget
) it is stated that it implements the ITrackableEventHandler
interface and when implementing your own custom event-handler behavior, you should consider deriving from this class, instead of making changes to it directly.
However, when I do so and include my own custom code in the override
methods after base.OnTrackingFound()
and base.OnTrackingLost()
, the code is never executed...
In the beginning, both virtual
and override
Start()
methods (in DefaultTrackableEventHandler.cs
and my own custom class) execute, but the OnTrackingFound
and OnTrackingLost
are not reached. My own script is attached to the same ImageTarget
.
What am I missing?
p.s. All the tutorials I see online disregard this advice and either copy & paste the same code for OnTrackingFound
and OnTrackingLost
(i.e. duplicate it) and then add their custom code, or add their custom code directly in the DefaultTrackableEventHandler.c
s script...
using UnityEngine;
public class WaitState : DefaultTrackableEventHandler
{
public GameObject _InfoCanvas;
protected override void Start()
{
Debug.Log("WaitState.Start()");
}
protected override void OnTrackingFound()
{
base.OnTrackingFound();
Debug.Log("WaitState.OnTrackingFound()");
_InfoCanvas.SetActive(false);
}
protected override void OnTrackingLost()
{
base.OnTrackingLost();
Debug.Log("WaitState.OnTrackingLost()");
_InfoCanvas.SetActive(true);
}
}