Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

AR-Foundation prefab spawned with offset

Discussion in 'AR' started by Press87, Jul 8, 2020.

  1. Press87

    Press87

    Joined:
    Oct 1, 2016
    Posts:
    1
    Good Morning, with ARfoundation and Image tracking when instantiate a prefab, the model not appears at marker position, but have some offset and looks weird..where is the problem? thanks
    the code:

    public class Game_Interactions : MonoBehaviour
    {
    [Header("The length of this list must match the number of images in Reference Image Library")]
    [SerializeField]
    private GameObject[] placedprefs;
    public Text testo;
    private GameObject test;


    private ARTrackedImageManager arTrackedImageManager;
    void Awake()
    {
    arTrackedImageManager =FindObjectOfType<ARTrackedImageManager>();
    }
    private void OnEnable()
    {
    arTrackedImageManager.trackedImagesChanged += OnImageChanged;
    }
    private void OnDisable()
    {
    arTrackedImageManager.trackedImagesChanged -= OnImageChanged;
    }
    public void OnImageChanged(ARTrackedImagesChangedEventArgs _args)
    {
    foreach(ARTrackedImage track in _args.added)
    {
    placeobject(track);
    }

    }
    public void placeobject(ARTrackedImage tracker)
    {

    if (tracker.referenceImage.name == "civita_attuale")
    {
    testo.text = tracker.referenceImage.name;
    test = Instantiate(placedprefs[0], tracker.transform.position
    , tracker.transform.rotation) as GameObject;
    }
    }

    }
     
unityunity