Reality Composerで編集
Xcodeで編集
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()
//追記「tapped」は上記図の赤枠で設定
boxAnchor.actions.tapped.onAction = handleTapOnEntity(_:)
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
//関数を追記
func handleTapOnEntity(_ entity: Entity?) {
guard let entity = entity else { return }
// Do something with entity...
print(entity) //Do something
}
}