Log in or register to post comments

DeployStageOnce.cs doesn´t show the field Anchor Stage

July 4, 2019 - 10:41am #1

Hi, guys.

I'm using DeployStaceOnce.cs, as in this link:

https://www.instructables.com/id/Augmented-Reality-Vuforia-7-Ground-Plane-Detection/

In this tutorial, the author said to remove the default Content Positioning Behavior script and then drag the DeploysStageOnce.cs into the Plane Finder.

After that, a field called Anchor Stage must be active for me to drag the Ground Plane Stage into it. But the problem is that this field, Anchor Stage, does not appear to me.

 

 

The code is:

using System;
using UnityEngine;
using Vuforia;
 
public class DeployStageOnce : MonoBehaviour {
     
    public GameObject AnchorStage;
    private PositionalDeviceTracker _deviceTracker;
    private GameObject _previousAnchor;
     
    public void Start ()
    {
        if (AnchorStage == null)
        {
            Debug.Log("AnchorStage must be specified");
            return;
        }
 
        AnchorStage.SetActive(false);
    }
 
    public void Awake()
    {
        VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    }
 
    public void OnDestroy()
    {
        VuforiaARController.Instance.UnregisterVuforiaStartedCallback(OnVuforiaStarted);
    }
 
    private void OnVuforiaStarted()
    {
        _deviceTracker = TrackerManager.Instance.GetTracker<PositionalDeviceTracker>();
    }
 
    public void OnInteractiveHitTest(HitTestResult result)
    {
        if (result == null || AnchorStage == null)
        {
            Debug.LogWarning("Hit test is invalid or AnchorStage not set");
            return;
        }
 
        var anchor = _deviceTracker.CreatePlaneAnchor(Guid.NewGuid().ToString(), result);
 
        if (anchor != null)
        {
            AnchorStage.transform.parent = anchor.transform;
            AnchorStage.transform.localPosition = Vector3.zero;
            AnchorStage.transform.localRotation = Quaternion.identity;
            AnchorStage.SetActive(true);
        }
 
        if (_previousAnchor != null)
        {
            Destroy(_previousAnchor);
        }
 
        _previousAnchor = anchor;
    }
}
Log in or register to post comments