Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

mid air - vuforia

Discussion in 'Vuforia' started by davejones1, Mar 20, 2018.

  1. davejones1

    davejones1

    Joined:
    Jan 19, 2018
    Posts:
    183
    I am using the mid air Vuforia feature to place content in the real world. The script attached is used to place content into the world when the user touches the screen. So far the script is used to place content once the user taps on the screen and the content moves when the user taps in a new location.

    I am looking at a way to change it so that the user can only place content once. After they have placed the content when tapping on the screen they wont be able to tap on the screen again to move the content. Does anyone have a solution?

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using Vuforia;
    4. public class DeployStageOnce : MonoBehaviour {
    5.  
    6.     public GameObject AnchorStage;
    7.     private PositionalDeviceTracker _deviceTracker;
    8.     private GameObject _previousAnchor;
    9.  
    10.     public void Start ()
    11.     {
    12.         if (AnchorStage == null)
    13.         {
    14.             Debug.Log("AnchorStage must be specified");
    15.             return;
    16.         }
    17.         AnchorStage.SetActive(false);
    18.     }
    19.     public void Awake()
    20.     {
    21.         VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
    22.     }
    23.     public void OnDestroy()
    24.     {
    25.         VuforiaARController.Instance.UnregisterVuforiaStartedCallback(OnVuforiaStarted);
    26.     }
    27.     private void OnVuforiaStarted()
    28.     {
    29.         _deviceTracker = TrackerManager.Instance.GetTracker<PositionalDeviceTracker>();
    30.     }
    31.     public void OnInteractiveHitTest(HitTestResult result)
    32.     {
    33.         if (result == null || AnchorStage == null)
    34.         {
    35.             Debug.LogWarning("Hit test is invalid or AnchorStage not set");
    36.             return;
    37.         }
    38.         var anchor = _deviceTracker.CreatePlaneAnchor(Guid.NewGuid().ToString(), result);
    39.         if (anchor != null)
    40.         {
    41.             AnchorStage.transform.parent = anchor.transform;
    42.             AnchorStage.transform.localPosition = Vector3.zero;
    43.             AnchorStage.transform.localRotation = Quaternion.identity;
    44.             AnchorStage.SetActive(true);
    45.         }
    46.         if (_previousAnchor != null)
    47.         {
    48.             Destroy(_previousAnchor);
    49.         }
    50.         _previousAnchor = anchor;
    51.     }
    52. }
    53.  
     
    yyuvraj54y1 likes this.