Back to All Posts

ARCore Unity Augmented images, Multiple images

August 16, 2018

I’ve been playing with the Unity ARCore SDK for sometime now. In the latest release they have added Augmented Images, which is awesome!

The first thing Myself and a few others wanted to do was track multiple images with multiple objects. For me I wanted 2 images to represent 2 different objects.

The Modification

We need to modify the AugmentedImageVisualizer to add a list of prefabs that we want. When the Image Visualiser is updated, check for the Image and update the position of the specific object.

public class AugmentedImageVisualizer : MonoBehaviour
{
    public AugmentedImage Image;
    public List<GameObject> prefabs;
    public void Update()
    {
        if (Image == null || Image.TrackingState != TrackingState.Tracking)
        {
            prefabs[Image.DatabaseIndex].SetActive(false);
            return;
        }
        prefabs[Image.DatabaseIndex].transform.localPosition = Image.CenterPose.position;
        prefabs[Image.DatabaseIndex].transform.forward = Image.CenterPose.forward;
        prefabs[Image.DatabaseIndex].SetActive(true);
    }
}