I've developed an AR app with unity extension. It has one image target. When the trackable is found, it shows animated objects and some static objects.
In the Unity project, the hierarchy is as follows.
ImageTarget
--> root
---> character
---> ground
---> bg
.....
That is, the "root" game object has all 3d objects as its children, and it is a child of ImageTarget.
I want to add more image targets with the same AR objects. So, I'm trying to use transform.parent after I read some relevant postings. But it seems not quite successful.
Here is my trial.
- I have two image targets, ImageTarget for image 'A' and ImageTarget for image 'B'.
- ImageTarget for 'A' has 'root' object mentioned above as an its child.
- When 'B' is found, 'root' object's parent is changed to 'B'
the code snippet is shown below.
It is good to add rotation as well if your model rotation is not following standard.
GameObject obj = GameObject.FindGameObjectWithTag("root");
obj.transform.parent = mTrackableBehaviour.transform;
obj.transform.position = mTrackableBehaviour.transform.position;
obj.transform.rotation = mTrackableBehaviour.transform.rotation;