Each time ARKit receives new information about an anchor, it will call this method. We do the same as we did with the previous code and iterate through the list to update the extent and position of the anchor object in the scene, as follows:
- In the WhackABox.iOS project, open the Game.cs file.
- Add the OnUpdateAnchors() method anywhere in the class, as shown in the following code snippet:
private void OnUpdateAnchors(ARAnchor[] anchors)
{
foreach (var anchor in anchors.OfType<ARPlaneAnchor>())
{
UpdateOrAddPlaneNode(anchor);
}
}
The code is a copy of the OnAddAnchors() method. It updates all nodes in the scene based on the information provided by ARKit.
We also need to write some code to remove the anchors that ARKit has removed.