Change 3d model by touching it with ARCore in Unity
I use ARCore 1.17 unity package and I use the example that is given in the package. It works fine, but now I want to change the 3d model by touching the model. I cannot find a way to do that. I found out how to get the touch recognized and it shows on screen the touch phases, in AugmentedImageVisualizer > Update() I have these lines:
if (Input.touchCount > 0)
{
theTouch = Input.GetTouch(0);
phaseDisplayText.text = theTouch.phase.ToString();
MyModel.SetActive(false);
GameObject.Destroy(MyModel);
if (theTouch.phase == TouchPhase.Ended)
{
Debug.Log("touch ended");
timeTouchEnded = Time.time;
}
}
else if (Time.time - timeTouchEnded > displayTime)
{
phaseDisplayText.text = "";
}
However, the MyModel.SetActive(false) does not make model to disappear. In the AugmentedImageVisualizerController is where I initially set the model on anchor that is placed on the recognized image:
Debug.Log("image.Name: " + image.Name);
Anchor anchor = image.CreateAnchor(image.CenterPose);
visualizer = (AugmentedImageVisualizer)Instantiate(
prefabs[1], anchor.transform);
visualizer.Image = image;
m_Visualizers.Add(1, visualizer);
Note: I have 2 prefabs that are used for 2 different images. When image0 is recognized, prefab0 is used and if image1 is recognized, prefab1 is used. In prefab1 I have 7 models, first model is setactive true (in Inspector the gameobject's checkbox is marked and for rest 6 have unmarked). When image 1 is recognized, model 1 out of the 7 appears, but touching the model does not set active false the current visible model (MyModel.SetActive(false)) and I cannot even get there to change the models.