- Home /
Question by
SallarQ · Nov 01, 2018 at 04:55 PM ·
c#unity 5vuforiaaugmented reality
Combine Two Image Targets to generate a model (Unity + Vuforia)
I want to generate a model when two Image targets combined or come closer to each other i tried to achieve this but i m not good at programming may be someone may help me i used below code and attached this script to both Image Targets
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class MTrackableBehaviour : MonoBehaviour, ITrackableEventHandler
{
protected TrackableBehaviour mTrackableBehaviour;
public bool isTracked = false;
public GameObject model_3;
protected virtual void Awake()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
trackedBehaviour();
}
else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
newStatus == TrackableBehaviour.Status.NOT_FOUND)
{
trackLostBehaviour();
}
else
{
trackLostBehaviour();
}
}
private void trackedBehaviour()
{
if (isBothTargetsTracked() == 2)
{
model_3.SetActive(true);
}
else
{
model_3.SetActive(false);
}
}
private void trackLostBehaviour()
{
model_3.SetActive(false);
}
private int isBothTargetsTracked()
{
int count = 0;
foreach (MTrackableBehaviour m in FindObjectsOfType<MTrackableBehaviour>())
{
if (m.mTrackableBehaviour.Trackable.Name == "1")
{
count++;
}
else if (m.mTrackableBehaviour.Trackable.Name == "2")
{
count++;
}
}
return count;
}
}
Please help me i will be very thankful..
@vuforia @Bunny83 @robertbu @Eric5h5 @tanoshimi @whydoidoit @FatWednesday @DaveA @ashfaqueck
Comment