问题描述
我正在尝试在Unity3D上使用ARToolKit SDK实现一些自定义行为。
根据文档
由于使用了BroadcastMessage,因此事件接收器和所有子代都将接收到该消息,因此,如果您需要调用多个GameObject,将它们放在一个组中,并使父对象成为事件接收器。
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.
The documentation is a bit out of date, as since ARToolKit for Unity v5.2 those events are generated by the ARTrackedObject component. The object that is to receive the events must be connected to the "Event receiver" on the ARTrackedObject, this is exposed in the Editor:
Since BroadcastMessage is used, the event receiver and any children will all receive the message, so if you need more than one GameObject to be called, put them into a group and make the parent object the event receiver.
这篇关于无法调用OnMarkerFound事件-Unity3D ARToolKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!