Let's add some code. The OnAddAnchor() method will be called each time ARKit updates its collection of anchors that describe points that we will use to relate to within our virtual world. We are specifically looking for anchors of the ARPlaneAnchor type.
Add the OnAddAnchor()( method to the Game.cs class by going through the following two steps:
- In the WhackABox.iOS project, open the Game.cs file.
- Add the OnAddAnchor() method anywhere in the class, as shown in the following code snippet:
private void OnAddAnchor(ARAnchor[] anchors)
{
foreach (var anchor in anchors.OfType<ARPlaneAnchor>())
{
UpdateOrAddPlaneNode(anchor);
}
}
The method takes an array of ARAnchors as a parameter. We filter out the anchors that are of the ARPlaneAnchor type and iterate through the list. For each ARPlaneAnchor object, we call the UpdateOrAddPlaneNode() method that we created earlier to add a node to the scene. Let's now...