I am a newbie in developing apps for Apple ecosystem. Currently, I’m working on a visionOS app, and I’d like to get model entities to be highlighted on eye focused, and back to normal when unfocused, something like a 3D button. The last thing I want to implement is that when focused/unfocused, I want it to call some functions as well.
I was able to get the individual entity to be highlighted on focused, however, the callback action when focused/unfocused is yet to be solved.
The following code is my attempt to the problem:
var body: some View {
ZStack {
RealityView { content in
// Loop through LightIDs enum and create model entities
for lightID in LightIDs.allCases {
let model = ModelEntity(
mesh: .generateSphere(radius: uniformedScale),
materials: [SimpleMaterial(color: .red, isMetallic: false)]
)
let x = Float.random(in: -1.0 ... 1.0)
model.position = SIMD3(x, 1.0, -2.0)
model.name = lightID.rawValue
model.components.set(InputTargetComponent())
model.components.set(HoverEffectComponent())
model.components.set(CollisionComponent(shapes: [.generateSphere(radius: uniformedScale)]))
content.add(model)
// model.onHover { hover in <-- error ModelEntity has no member onHover
// if hover {
// print("Mouse hover: (model.name)")
// // do something else here
// }
// }
}
}
}
}
If anyone has any insight to this issue, that would be greatly appreciated.