Reputation: 3519
I want to create virtual objects on tap.
I know that I can use the gesture
call to react to gestures, but I don't see how I can access the RealityViewContent from there in order to add it to the scene or subscribe to collision events.
RealityView { content in
...
}.gesture(TapGesture().targetedToAnyEntity().onEnded{ event in
let o = create_a_square()
// I want to do this:
content.add(o);
content.subscribe(to: CollisionEvents.Began.self, on: o) ..
}
Upvotes: 0
Views: 28
Reputation: 3519
For adding / removing entities in gestures (or other locations):
Apple's sample code adds an entity** to content
, stores it in an environment variable add uses rootEntity.addChild
and rootEntity.removeChild
later for accessing.
** In the SceneReconstruction example by Apple it's called model
. Other common names might be rootEntity.
For accessing content
to subscribe to events:
You can go with the same logic
Upvotes: 0