Log in or register to post comments

Swap Model Via Button

July 28, 2016 - 8:32pm #1

I wanted to swap model by pressing a button and here is my codes however when I press the button my existing model just disappears and the one that is supposed to replace it doesnt show what could be the problem?

public class ModelSwap : MonoBehaviour
{

    public TrackableBehaviour theTrackable;
    private bool mSwapModel = false;

    // Use this for initialization
    void Start()
    {
        if (theTrackable == null)
        {
            Debug.Log("Trackabale 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"))
        {
            mSwapModel = true;
        }
    }

    private void SwapModel()
    {
        GameObject trackableGameObject = theTrackable.gameObject;

        for (int i = 0; i < trackableGameObject.transform.childCount; i++)
        {
            Transform child = trackableGameObject.transform.GetChild(i);
            child.gameObject.SetActive(false);
        }

        GameObject Baker_house = GameObject.Find("Baker_house");

        Baker_house.transform.parent = theTrackable.transform;
        Baker_house.transform.localPosition = new Vector3(0, 0.2f, 0);
        Baker_house.transform.localRotation = Quaternion.identity;
        Baker_house.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

        Baker_house.SetActive(true);
    }
}

Swap Model Via Button

August 1, 2016 - 6:49pm #2

Found an alternate solution

void Start(){

model2.SetActive(false)

}

 

void ModelSwitch(){

model1.SetActive(false);

model2.SetActive(true);

}

 

And I just called the model switch on my button.

 

Log in or register to post comments