I'm getting below error while using below code:
Assets/ModelSwapper.cs(13,17): error CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `TrackableBehaviour'
Assets/ModelSwapper.cs(14,11): error CS0103: The name `cube' does not exist in the current context
using UnityEngine;
using System.Collections;
public class ModelSwapper : MonoBehaviour {
public TrackableBehaviour theTrackable;
private bool mSwapModel = false;
// Use this for initialization
void Start () {
theTrackable=GameObject.Find("Dog");
cube = GameObject.Find("Dear");
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 cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
// Re-parent the cube as child of the trackable gameObject
cube.transform.parent = theTrackable.transform;
// Adjust the position and scale
// so that it fits nicely on the target
cube.transform.localPosition = new Vector3(0,0.2f,0);
cube.transform.localRotation = Quaternion.identity;
cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
// Make sure it is active
cube.active = true;
}
}
I tried the below code what you given from the link. But i can't swap the model..When i point stones target i need to display cow model, when i point tarmac i need to display elephant. But 2 models displaying for both target. Please help this. What should i change in code? I tried from this link also : https://developer.vuforia.com/forum/faq/unity-how-can-i-dynamically-attach-my-3d-model-image-target. This is only for chips target. How can i do it for another target. Please give some tips..