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); }}
Found an alternate solution
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.