我学习增强现实并遇到问题。我想使用一个图像目标,但我有很多图片(在我的vuforia
数据库中)。我只能读一张图片,但对我来说这是个问题。我必须扫描很多标记(我会读取不同的标记,但足够一个图像目标)
我必须感知这个图像名称并使用循环。我在互联网上使用了代码,但它们不起作用。
如何解决这个问题?
你能帮我吗?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Vuforia;
public class DynamicTargets : MonoBehaviour
{
private bool mChipsObjectCreated = false;
// Update is called once per frame
void Update()
{
// mChipsObjectCreated = false;
IEnumerable<TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager().GetActiveTrackableBehaviours();
// Loop over all TrackableBehaviours.
foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)
{
string name = trackableBehaviour.TrackableName;
Debug.Log("Trackable name: " + name);
while (name.Equals("photo") && !mChipsObjectCreated)
{
// chips target detected for the first time
// augmentation object has not yet been created for this target
// let's create it
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
// attach cube under target
cube.transform.parent = trackableBehaviour.transform;
// Add a Trackable event handler to the Trackable.
// This Behaviour handles Trackable lost/found callbacks.
trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();
// set local transformation (i.e. relative to the parent target)
cube.transform.localPosition = new Vector3(0, 0.2f, 0);
cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
cube.transform.localRotation = Quaternion.identity;
cube.gameObject.SetActive(true);
mChipsObjectCreated = true;
}
}
}
}