0

I was watching a 3-year-old tutorial for Vuforia and it's freezing the content and modifying it instead of the possibility of an uncomfortable position. the code looked fine and very well explained although I'm using TrackableBehaviour and it keeps showing me an error that it doesn't exist, at first thought I might didn't download Vuforia correctly, but I don't think this is the case anymore. if someone knows what is the problem or an alternative solution please tell me.

c#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class TIH : MonoBehaviour
{
    public GameObject picture; // Reference to the augmentable picture GameObject
    private TrackableBehaviour trackableBehaviour; // Reference to the TrackableBehaviour component
    private float touchTime; // Stores the time when the touch begins
    private bool isPictureFrozen = false; // Flag to check if the picture is frozen

    void Start()
    {
        // Get the TrackableBehaviour component of the augmentable picture
        trackableBehaviour = picture.GetComponentInParent<TrackableBehaviour>();
    }

    void Update()
    {
        if (Input.touchCount == 1) // Single touch
        {
            Touch touch = Input.GetTouch(0); // Get the touch
            if (touch.phase == TouchPhase.Began) // Touch started
            {
                touchTime = Time.time; // Store the time when the touch began
            }
            else if (touch.phase == TouchPhase.Ended && (Time.time - touchTime) >= 1.0f && !isPictureFrozen) // Touch ended, duration >= 1 second, and picture not frozen
            {
                FreezePicture(); // Freeze the picture
            }
        }
        else if (Input.touchCount == 2) // Two-finger touch
        {
            Touch touch1 = Input.GetTouch(0); // Get the first touch
            Touch touch2 = Input.GetTouch(1); // Get the second touch

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved) // One or both touches moved
            {
                float pinchDistance = Vector2.Distance(touch1.position, touch2.position); // Calculate the distance between the two touches
                float pinchDelta = (touch1.deltaPosition - touch2.deltaPosition).magnitude; // Calculate the change in distance between the two touches

                // Scale the picture based on the pinch gesture
                picture.transform.localScale *= 1 + pinchDelta * Time.deltaTime;
            }
        }
    }

    private void FreezePicture()
    {
        isPictureFrozen = true; // Set the flag to indicate the picture is frozen
        trackableBehaviour.enabled = false; // Disable the TrackableBehaviour component to stop tracking the augmentable image
    }
}

tried to redownload the vuforia package, download another version of unity that might be supported, nothing worked.

shingo
  • 18,436
  • 5
  • 23
  • 42
  • Hello and welcome! Instead of adding `c#` into your question body, you can add a tag for [tag:c#] to help this be found better by the right people :) _just FYI I have done this for you_ – Can O' Spam May 05 '23 at 09:20

1 Answers1

0

I found the answer on this page:

https://library.vuforia.com/project-migration/how-migrate-unity-project#model-targets

"The TrackableBehaviour base class has been deprecated and replaced with the ObserverBehaviour. Furthermore, the ObserverBehaviour and all subclasses no longer expose a Trackable member. All properties and methods previously exposed through that member object are now directly available through the ObserverBehaviour classes."

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34575661) – AztecCodes Jun 26 '23 at 11:40