0

I am trying to get some custom behaviour implemented using ARToolKit SDK on Unity3D.
According to the documentation here, the ARCamera uses the BroadcastMessage system to call OnMarkerFound(ARMarker marker) and OnMarkerLost(ARMarker marker) to notify when a marker is found or lost.
However, I cannot get these functions to fire at all. I have gone through the entire source code, added debug watches, the works... But these two events are not firing.
My script looks like this:

using UnityEngine;
using System.Collections;

public class CustomTrack : MonoBehaviour {
    void OnMarkerFound(ARMarker marker){
        Debug.Log("MARKER FOUND! WHEEEE!");
    }

    void OnMarkerLost(ARMarker marker){
        Debug.Log("MARKER LOST! WHEEEE!");
    }

    void OnMarkerTracked(ARMarker marker){
         Debug.Log("MARKER TRACKED! WHEEEE!");
    }
}

I have seen several other people on forums, etc. facing similar problems so it would be nice to finally have a solution to this issue.


EDIT - Answer

Just to explain what I did to get this working, going by what @bleater said, I added the GameObject to the ARTrackedObject and then added my CustomScript to the GameObject. One mistake I was making was to attach the CustomScript to the ARMarkerScene. So, that worked. I hope this is useful to others as well.

4

1 回答 1

2

文档有点过时,因为自从 ARToolKit for Unity v5.2 以来,这些事件是由 ARTrackedObject 组件生成的。接收事件的对象必须连接到 ARTrackedObject 上的“事件接收器”,这在编辑器中公开:

ARTrackedObject 的 Unity 编辑器面板

由于使用了BroadcastMessage,事件接收者和所有子对象都会收到消息,所以如果需要调用多个GameObject,请将它们归为一组,并让父对象成为事件接收者。

于 2016-02-11T22:34:02.477 回答