To enable user defined target (UDT) events, we need to add Vuforia's UDT Event Handler component to the UserDefinedTargetBuilder:
- With UserDefinedTargetBuilder selected in Hierarchy, Add Component UDT Event Handler.
- Drag the UserDefinedTarget from Hierarchy onto the Image Target Template slot.
Now we can tell the button that OnClick events should call the BuildNewTarget() function:
- In the Capture Target Button's Inspector, press the + on OnClick().
- Drag the UserDefinedTargetBuilder onto the Object slot.
- And set the function to BuildNewTarget().
The following screenshot shows the Capture Button OnClick setup for the UDT Event Handler:
Save your work. Now when you press Play, point your webcam at a target and press Capture. Whenever the camera sees and recognizes that camera view, it will render the AR content. For now, it's the cube.
In the following screenshot, I am testing the app with a toy truck on my desk (a real car wouldn't fit in my office). I captured its tire as the target.
Now let's try it with the AR View too:
- Re-enable the Content Scroll View object.
You'll notice that the Capture Target button is still visible.
- Move the AR Prompt panel up in the Hierarchy so it's just under the Nav Panel, as shown in the following screenshot:
Now press Play. Then press AR View and press Capture Target. Voila!
You might want to disable Content Scroll View again as we proceed.