I need to display 3d model for each target. I need to display cow for stones target, elephant for tarmac target. But when i open the camera the models are showing on the overlay. I tried with swap. But the swap when i click the button it remove the model. But i don't want to with button click. When i point to stones need to display only cow, when i point to tarmac need to display elephant. I use one scene. I choosed Dataset, ImageTarget for stones. Then drag the cow. Then choosed tarmac in Dataset then drag the elephant . But when i point to stones or tarmac the 2 models are showing. I searched for swap the model. Also i wrote the code for swap:
using UnityEngine;
using System.Collections;
public class ModelSwapper : MonoBehaviour {
// public TrackableBehaviour theTrackable;
private GameObject theTrackable;
private GameObject cube;
private bool mSwapModel = false;
public Transform MyPrefab;
// Use this for initialization
void Start () {
theTrackable=GameObject.Find("Cow N050213");
cube = GameObject.Find("Cow N050213");
if (theTrackable == null)
{
Debug.Log ("Warning: Trackable not set !!");
}
}
// Update is called once per frame
void Update () {
if (mSwapModel && theTrackable != null) {
SwapModel();
mSwapModel = false;
}
}
void OnGUI() {
if (GUI.Button (new Rect(50,50,120,40), "Swap Model")) {
mSwapModel = true;
}
}
private void SwapModel()
{
GameObject trackableGameObject = theTrackable.gameObject;
//disable any pre-existing augmentation
for (int i = 0; i < trackableGameObject.transform.GetChildCount(); i++)
{
Transform child = trackableGameObject.transform.GetChild(i);
child.gameObject.active = false;
}
// Create a simple cube object
//GameObject model = GameObject.CreatePrimitive(PrimitiveType.Cube);
if (MyPrefab != null)
{
Transform model = GameObject.Instantiate(MyPrefab) as Transform;
// Re-parent the model as child of the trackable gameObject
model.parent = theTrackable.transform;
// Adjust the position and scale
// so that it fits nicely on the target
model.transform.localPosition = new Vector3(0,0.2f,0);
model.transform.localRotation = Quaternion.identity;//you might need to adjust the rotation
model.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
// Make sure it is active
model.active = true;
}
}
}
just use multiple Imagetargets and asign the Models as child to the imagetarget you want...