I am trying make my prefabs appear at runtime on my imagetarget by following this link vuforia instantiate prefab on imagetarget dynamically
the only difference is that I want to be able to drag some prefabs that I created instead of only one prefab shown in the tutorial.
public GameObject[] prefabModels;
my problem is even after my imagetarget is detected all my 3d prefabs didn't show up.
this code is attached to my imagetarget object
using System;
using UnityEngine;
using System.Collections;
using Vuforia;
public class ImageTargetMgr : MonoBehaviour, ITrackableEventHandler {
private TrackableBehaviour mTrackableBehaviour;
public GameObject[] prefabModels;
// Use this for initialization
void Start () {
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
}
// Update is called once per frame
void Update () {
}
public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}
private void OnTrackingLost()
{
}
private void OnTrackingFound()
{
Debug.Log("Image Target Found!");
foreach (GameObject o in prefabModels)
{
if (o != null)
{
Debug.Log("Currently instantiated models is " + o.name);
GameObject myPrefab = Instantiate(o, Vector3.zero, Quaternion.identity) as GameObject;
myPrefab.transform.parent = mTrackableBehaviour.transform;
myPrefab.transform.localPosition = new Vector3(0.0f, 10.0f, 0.0f);
myPrefab.transform.localRotation = Quaternion.identity;
//o.transform.localScale = new Vector3(1000.0f, 1000.0f, 1000.0f);
myPrefab.gameObject.SetActive(true);
}
}
}
here are the log and what shown on hierarchy when running the scene
hope I will get some helps here..cheers