2017年1月9日 星期一

[Unity 3D] Keeping the object on the screen even when the target is lost


讓AR Camera 偵測到目標物後,產生的虛擬物件不會消失的方法有兩種:

The first one : 設定屬性
Step 1 : 要把ImageTarget 放到 ARCamera階層下.
Step 2 : Enable Extended Tracking 的選項打勾.

The Second one : 修改腳本
The script that handles what happens when tracking is lost is called DefaultTrackableEventHandler.cs and is found in Assets > Vuforia > Scripts. 
In that file you will find a function OnTrackingLost() This function disables all the renderComponents and colliderComponents for each of the children of the ImageTarget. If you want your object to stay visible comment out the following foreach loops like so:
private void OnTrackingLost()  //當目標物遺失就執行這方法
{
    Renderer[] rendererComponents = GetComponentsInChildren(true);
    Collider[] colliderComponents = GetComponentsInChildren(true);
    /*
    // Disable rendering:
    foreach (Renderer component in rendererComponents)
    {
        component.enabled = false;  //把false改成true,當目標物遺失虛擬物件不會跟著消失
    }

    // Disable colliders:
    foreach (Collider component in colliderComponents)
    {
        component.enabled = false;   //把false改成true,當目標物遺失虛擬物件不會跟著消失

    }
    */
    Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}

沒有留言: