Skip to main content

Button Effekt in VR

Zeigt einen Button in einem virtuellen Raum, der beim Anklicken einen entsprechenden Effekt bekommt.

import SwiftUI
import RealityKit
import RealityKitContent

struct ContentView: View {
    var body: some View {
        ZStack {
            RealityView { content in
                let box = ModelEntity(mesh: .generateBox(size: 0.1))
                box.position = [0, 0, -0.5]
                content.add(box)
            }

            VStack {
                Spacer()
                HStack {
                    Spacer()
                    Button(action: {
                        print("AR Button Pressed")
                    }) {
                        Label("Interact", systemImage: "hand.tap")
                            .padding()
                            .background(.ultraThinMaterial)
                            .clipShape(Capsule())
                    }
                    .padding()
                }
            }
        }
        .edgesIgnoringSafeArea(.all)
    }
}