我正在观看一个 3 年前的 Vuforia 教程,它冻结了内容并对其进行了修改,而不是可能出现不舒服的位置。尽管我使用的是 TrackableBehaviour 并且它一直向我显示它不存在的错误,但代码看起来很好并且解释得很好,起初我以为我可能没有正确下载 Vuforia,但我认为情况并非如此了。如果有人知道问题是什么或替代解决方案,请告诉我。
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
}
}
尝试重新下载 vuforia 包,下载另一个可能支持的 unity 版本,但没有任何效果。