Hello everyone, I have just started learning the development and learning of visionPro app. I have a scene called Scene, and inside it is an object called Sphere. I want to add a drag animation to this Sphere alone. I follow the code below to achieve it. But my Sphere cannot actually be dragged in the Apple simulator. What is the reason?
struct ContentView: View {
@State var enlarge = false
@State var offset: Point3D = .zero
@State var sphereEntity: Entity?
var body: some View {
RealityView { content in
if let scene = try? await Entity(named: "Scene", in: realityKitContentBundle) {
content.add(scene)
sphereEntity = content.entities.first?.findEntity(named: "Sphere")
sphereEntity?.components.set(InputTargetComponent(allowedInputTypes: .all))
}
}.gesture(DragGesture().targetedToEntity(sphereEntity ?? Entity()).onChanged({ value in
print(value.location3D)
sphereEntity?.position = value.convert(value.location3D, from: .local, to: sphereEntity?.parent! ?? Entity())
}))
.gesture(SpatialTapGesture().targetedToAnyEntity().onEnded({ _ in
print("Ssssssss")
})) .onAppear() {
}
}
}