If you get errors like:
1)Assets/VuforiaAddedScripts/DeployStageOnce.cs(50,51): error CS1061: Type `Vuforia.Anchor' does not contain a definition for `transform' and no extension method `transform' of type `Vuforia.Anchor' could be found. Are you missing an assembly reference?
2)Assets/VuforiaAddedScripts/DeployStageOnce.cs(61,27): error CS0029: Cannot implicitly convert type `Vuforia.Anchor' to `UnityEngine.GameObject'
This code will help you:
using System;
using UnityEngine;
using Vuforia;
public class DeployStageOnce : MonoBehaviour
{
public GameObject AnchorStage;
private PositionalDeviceTracker _deviceTracker;
private GameObject _anchorGameObject;
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>();
}
private void AnchorGameObjectSetHitTestPosition(HitTestResult reuslt)
{
_anchorGameObject.transform.position = reuslt.Position;
_anchorGameObject.transform.rotation = reuslt.Rotation;
}
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);
_anchorGameObject = new GameObject();
AnchorGameObjectSetHitTestPosition(result);
if(anchor != null) {
AnchorStage.transform.parent = _anchorGameObject.transform;
AnchorStage.transform.localPosition = Vector3.zero;
AnchorStage.transform.localRotation = Quaternion.identity;
AnchorStage.SetActive(true);
}
if(_previousAnchor != null) {
Destroy(_previousAnchor);
}
_previousAnchor = _anchorGameObject;
}
}
Hey Buddy !!!
I am Glad it works and it is not getting any errors for now. Hoping for the Best in Future if Error is not generated.