Wednesday, January 3, 2024
HomeiOS DevelopmentLearn how to subscribe to a AnimationController on RealityKit

Learn how to subscribe to a AnimationController on RealityKit


The next code strikes an entity all through the house when tapped. That works effective however how would I get an occasion notification (I think about a AnimationEvents.PlaybackCompleted)for when the animation finishes?

struct ImmersiveGameView: View {
    let entity = Utils.generateBall(colour: .inexperienced) //Generates a Entity sphere
    let viewModel = ImmersiveGameViewModel()

    var physique: some View {
        RealityView { content material in
            entity.setPosition(SIMD3(0, 1, -0.7), relativeTo: nil)
            content material.add(entity)
        }

        .gesture(SpatialTapGesture().targetedToAnyEntity().onEnded({ worth in
            var rework = Rework()
            rework.translation.z = entity.place.z - 10
            rework.translation.x = entity.place.x
            rework.translation.y = entity.place.y
            worth.entity.transfer(to: rework, relativeTo: nil, period: 2)
        }))
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments