private void RemoveExistingContent()
 {
     foreach (var image in m_TempAugmentedImages)
     {
         currentlyTracked = null;
         m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
         if (currentlyTracked != null)
         {
             m_TrackedImages.Remove(image.DatabaseIndex);
             currentlyTracked.Remove();
         }
     }
 }
    public void Update()
    {
        //rotate objects with finger swipe feature
        if (Input.GetMouseButton(0))
        {
            //printToScreen.text = Input.GetTouch(0).deltaPosition.x.ToString();

            //make this check is its actively tracked first
            for (int i = 0; i < transform.childCount; i++)
            {
                //its a model, not a UI, so go rotate it
                if (transform.GetChild(i).GetChild(0).gameObject.tag == "3DModel")
                {
                    transform.GetChild(i).rotation = Quaternion.Euler(0f, transform.GetChild(i).rotation.eulerAngles.y + (Input.GetTouch(0).deltaPosition.x / 2f), 0f);
                }
            }
        }

        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (Session.Status != SessionStatus.Tracking)
        {
            Screen.sleepTimeout = SleepTimeout.SystemSetting;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        // Get updated augmented images for this frame.
        Session.GetTrackables <AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.All);

        if (removeExistingContent)
        {
            foreach (var image in m_TempAugmentedImages)
            {
                currentlyTracked = null;
                m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
                if (currentlyTracked != null)
                {
                    //testing if we should remove 3D models at this point and if its a 3D model
                    if (currentlyTracked.transform.GetChild(0).gameObject.tag == "3DModel")
                    {
                        if (remove3DContent)
                        {
                            m_TrackedImages.Remove(image.DatabaseIndex);
                            currentlyTracked.Remove();
                        }
                    }
                    else
                    { //its a UI element and remove it
                        m_TrackedImages.Remove(image.DatabaseIndex);
                        currentlyTracked.Remove();
                    }
                }
            }
            removeExistingContent = false;
            remove3DContent       = false;
        }
        else if (shouldControllerBeTracking)
        {
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                shouldImageBeTracked = gameManager.InputDetected(0);
                if (shouldImageBeTracked)
                {
                    currentlyTracked = (TrackedImage)Instantiate(
                        TrackedImagePrefab, this.transform);
                    currentlyTracked.transform.parent = this.transform;
                    m_TrackedImages.Add(0, currentlyTracked);
                    shouldImageBeTracked = false;
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                shouldImageBeTracked = gameManager.InputDetected(7);
                if (shouldImageBeTracked)
                {
                    currentlyTracked = (TrackedImage)Instantiate(
                        TrackedImagePrefab, this.transform);
                    currentlyTracked.transform.parent = this.transform;
                    m_TrackedImages.Add(7, currentlyTracked);
                    shouldImageBeTracked = false;
                }
            }

            // Create an anchor and a model for updated augmented images that are tracking and do
            // not previously have a model. Remove models for stopped images.
            foreach (var image in m_TempAugmentedImages)
            {
                currentlyTracked = null;
                m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
                if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking && currentlyTracked == null) //image.TrackingState == TrackingState.Tracking &&
                {
                    //need to switch this to know the databaseElement right away if thats the one that should be spawned
                    shouldImageBeTracked = gameManager.InputDetected(image.DatabaseIndex);
                    if (shouldImageBeTracked)
                    {
                        // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        currentlyTracked = (TrackedImage)Instantiate(
                            TrackedImagePrefab, anchor.transform);
                        currentlyTracked.image  = image;
                        currentlyTracked.anchor = anchor;
                        //currentlyTracked.transform.rotation = Quaternion.identity;
                        currentlyTracked.transform.parent = this.transform;
                        m_TrackedImages.Add(image.DatabaseIndex, currentlyTracked);
                        shouldImageBeTracked = false;
                    }
                }
                else if (image.TrackingState == TrackingState.Stopped && currentlyTracked != null)
                {
                    m_TrackedImages.Remove(image.DatabaseIndex);
                    GameObject.Destroy(currentlyTracked.gameObject);
                }
            }
        }
    }