Log in or register to post comments

How to swap multiple images

December 20, 2013 - 5:44pm #1

I created ModelSwapper script and drag this script to ARCamera then choosen one 3d model for swap. How can i choose multiple 3d model 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 () {
 
mSwapModel = true;
 
theTrackable=GameObject.Find("dog");
cube = GameObject.Find("dog");
 
 
 
if (theTrackable == null)
 
        {
 
            Debug.Log ("Warning: Trackable not set !!");
 
        }
 
}
 
// Update is called once per frame
void Update () {
 
if (mSwapModel && theTrackable != null) {
            SwapModel();
            mSwapModel = false;
        }
 
}
 
 
    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;
 
        }
 
    }
}
 
Log in or register to post comments