Double-click the object to be displayed to display the setting screen and give it a name. In the case of the figure below, it is named "hako".
When you tap the object, "hako" is displayed on the debug screen.
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
boxAnchor.actions.tapped.onAction=clickEvent(_:)
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
func clickEvent(_ entity: Entity?) {
guard let entity = entity else { return }
print(entity.name)
}
}
"Tapped" is a behavior added by Reality Composer.