You could detach the object from the vuforia target - making it not a child but instead set it somewhere else in the hierachy - and only move it to the correct coordinates OnTargetFound
.
Add e.g. a UnityEvent<Transform>
like (this goes to the vuforia target)
[system.Serializable]
public class TransformEvent : UnityEvent<TargetFoundEventHandler>
{
}
public class TargetFoundEventHandler : DefaultTrackableEventHandler
{
public TransformEvent onTrackingFound;
protected override void OnTrackingFound()
{
onTrackingFound.Invoke(transform);
}
}
you can use that to reference callbacks (similar to the onClick
of Button
s) but those methods have to expect a TargetFoundEventHandler
parameter like (this goes to the object to place)
public class PlaceMeOnTarget()
{
public void PlaceOnTarget(TargetFoundEventHandler target)
{
transform.SetPositionAndRotation(target.transform.position, target.transform.rotation);
// optinally remove the callback so this object
// will not be placed elsewhere
target.onTrackingFound.RemoveListener(PlaceOnTarget);
}
}