Let's add a method to handle the removal of an ARPlaneAnchor object by going through the following steps:
- In the WhackABox.iOS project, open the Game.cs file.
- Add the OnRemoveAnchors() method anywhere in the class, as shown in the following code snippet:
private void OnRemoveAnchors(ARAnchor[] anchors)
{
foreach (var anchor in anchors.OfType<ARPlaneAnchor>())
{
FindNodeByPlaneId(anchor.Identifier.ToString())?.Remove();
}
}
As with the Add and Remove functions, this method accepts an array of ARAnchor. We iterate through this array, looking for anchors of the ARPlaneAnchor type. We then look for a node that represents this plane by calling the FindNodeByPlaneId() method. If it's not null, then we call for that node to be removed. Note the null-check operator before the Remove() call.