Hi,
I'ved used as starting point the core sample apps, scene: 3 - ImageTargets.
Moving forward I created script DelayedAugmentation.cs as below:
public class DelayedAugmentation : DefaultTrackableEventHandler
{
protected override void OnTrackingFound()
{
if(!coRoutineIsOn){
StartCoroutine(makeItVisible());
Debug.Log("Coroutine starting!!!");
}
}
private bool coRoutineIsOn = false;
public float waitingTime = 15f;
IEnumerator makeItVisible()
{
coRoutineIsOn = true;
yield return new WaitForSeconds(waitingTime);
if (mTrackableBehaviour)
{
var rendererComponents = mTrackableBehaviour.GetComponentsInChildren<Renderer>(true);
var colliderComponents = mTrackableBehaviour.GetComponentsInChildren<Collider>(true);
var canvasComponents = mTrackableBehaviour.GetComponentsInChildren<Canvas>(true);
// Enable rendering:
foreach (var component in rendererComponents)
component.enabled = true;
// Enable colliders:
foreach (var component in colliderComponents)
component.enabled = true;
// Enable canvas':
foreach (var component in canvasComponents)
component.enabled = true;
}
coRoutineIsOn = false;
}
protected override void OnTrackingLost()
{
if (coRoutineIsOn)
{
StopCoroutine(makeItVisible());
coRoutineIsOn = false;
}
if (mTrackableBehaviour)
{
var rendererComponents = mTrackableBehaviour.GetComponentsInChildren<Renderer>(true);
var colliderComponents = mTrackableBehaviour.GetComponentsInChildren<Collider>(true);
var canvasComponents = mTrackableBehaviour.GetComponentsInChildren<Canvas>(true);
// Disable rendering:
foreach (var component in rendererComponents)
component.enabled = false;
// Disable colliders:
foreach (var component in colliderComponents)
component.enabled = false;
// Disable canvas':
foreach (var component in canvasComponents)
component.enabled = false;
}
}
}
The above delays the initialization by 5 seconds. Time can be adjusted in Unity Editor.
I attached the script on the GameObject: ImageTarget_Astronaut and removed also DefaultTrackableEventHandler. ( as our script inherits from DefaultTrackableEventHandler)
Hit Play; In the console you will get the info that the image has been detected and the coroutine has started. After 5 seconds the Astronaut will appear.
Thank you.
Vuforia Engine Support
Hi,
I'ved used as starting point the core sample apps, scene: 3 - ImageTargets.
Moving forward I created script DelayedAugmentation.cs as below:
The above delays the initialization by 5 seconds. Time can be adjusted in Unity Editor.
I attached the script on the GameObject: ImageTarget_Astronaut and removed also DefaultTrackableEventHandler. ( as our script inherits from DefaultTrackableEventHandler)
Hit Play; In the console you will get the info that the image has been detected and the coroutine has started. After 5 seconds the Astronaut will appear.
Thank you.
Vuforia Engine Support