- Home /
Question by
jakelong00 · May 10, 2014 at 02:33 PM ·
destroyvuforiadetach
Destroying Object after spawing - Vuforia
I am trying to destroy the image target and make my model independent after the target has been detected, but for some reason my target is being detected even when I am not showing camera anything.
I am using the following code:
public void OnTrackableStateChanged(TrackableBehaviour.Status prevStatus, TrackableBehaviour.Status newStatus){
if(newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED &&){
OnTrackingFound();
}
else
{
if(!hasBeenDetected){
OnTrackingLost();
}
}
}
private void OnTrackingFound()
{
Debug.Log("in OnTrackingFound()");
hasBeenDetected = true;
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Trackable " + myTrackableBehaviour.TrackableName + " found");
DestroyAndDetachChild();//My function
}
//I haven't changed OnTrackingLost()
private void DestroyAndDetachChild(){
Debug.Log("in DestroyAndDetachChild");
gameObject.transform.DetachChildren();
gameObject.setActive(false);
}
Can someone tell me why is this behaving the way it is please?
Comment
I changed the if condition:
if(newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRAC$$anonymous$$ED)...
to
if(newStatus == TrackableBehaviour.Status.TRAC$$anonymous$$ED){...