The problem is that the camera olny augments the 3d model when it is tracking the image target. I have tried using extended tracking feature but still the 3D image disappears when the camera is not tracking the image target. Is there a way I can allow the 3d model to be pined on a certain location afeter the image target is tracked?
I tried using the script below and it’s giving me the following error message: The type or namespace name ‘ITrackableEventHandler’ could not be found(are you missing a using directive or an assembly reference?
using UnityEngine;
using Vuforia;
public class KeepObjectVisible : MonoBehaviour, ITrackableEventHandler
{
private TrackableBehaviour mTrackableBehaviour;
private bool isTracking = false;
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
newStatus == TrackableBehaviour.Status.NO_POSE)
{
OnTrackingLost();
}
else
{
OnTrackingLost();
}
}
private void OnTrackingFound()
{
isTracking = true;
SetChildrenActive(true);
}
private void OnTrackingLost()
{
isTracking = false;
// Here, we do not deactivate the children to keep the object visible.
}
void Update()
{
if (!isTracking)
{
// Logic to keep the object visible and possibly maintain its last known position.
}
}
private void SetChildrenActive(bool active)
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(active);
}
}
}
Takidzwa Brian Denhere is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.