0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ARFoundation 複数のImageに別のキャラを表示する

Last updated at Posted at 2021-07-26

Imageを設定し、サイズを調整する
2043B1CB-E53E-49D9-ADE5-55D65F3EADD7.jpeg

Characterのサイズを合わせる
59C8A8A9-93DC-4C7E-B424-431F1109454A_4_5005_c.jpeg

ImageManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class ImageManager : MonoBehaviour
{
    //イメージトラッキングの結果を取得するためのクラス
    ARTrackedImageManager m_TrackedImageManager;

    //画像に重ねて表示するPrefabのList
    [SerializeField]
    private List<GameObject> prefabs;

    void Start()
    {
        //GameObject にアタッチされている ARTrackedImageManager を取得
        m_TrackedImageManager = GetComponent<ARTrackedImageManager>();

        //ARTrackedImage の変更時に実行する関数をセット
        m_TrackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
    }

    //ARTrackedImageの変更時に実行される関数
    void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    {
        //新たに追加(検知)された画像に対して実行
        foreach (var trackedImage in eventArgs.added)
        {
            //ReferenceImage の Name が"image1"の画像に対する処理
            if (trackedImage.referenceImage.name == "image1")
            {
                //検知した画像を parent にして、Prefab から GameObject を作成する
                Instantiate(prefabs[0], trackedImage.transform);
            }
            //ReferenceImage の Name が"image2"の画像に対する処理
            if (trackedImage.referenceImage.name == "image2")
            {
                //検知した画像を parent にして、Prefab から GameObject を作成する
                Instantiate(prefabs[1], trackedImage.transform);
            }
        }
    }
}

ARSessionOriginのARTrackedImageManagerの値を変更し、ImageManager.csをアタッチして、プレハブをアタッチする
9A0DDFA3-66EE-4399-B9C3-8DFFD5B41546.jpeg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?