34 lines
1017 B
GDScript
34 lines
1017 B
GDScript
extends Area3D
|
|
|
|
@export var audio_player: AudioStreamPlayer3D
|
|
@export var right_controller: XRController3D
|
|
@export var activation_distance: float = 1.0 # 100cm Reichweite
|
|
var is_muted = false
|
|
var button_was_pressed = false
|
|
|
|
func _process(_delta):
|
|
if not right_controller:
|
|
return
|
|
|
|
# Prüfe Distanz zum Controller
|
|
var distance = global_position.distance_to(right_controller.global_position)
|
|
var button_pressed = right_controller.is_button_pressed("by_button")
|
|
|
|
# Toggle wenn nah genug und Button neu gedrückt
|
|
if distance < activation_distance and button_pressed and not button_was_pressed:
|
|
toggle_audio()
|
|
|
|
button_was_pressed = button_pressed
|
|
|
|
func toggle_audio():
|
|
is_muted = !is_muted
|
|
|
|
if audio_player:
|
|
audio_player.volume_db = -80.0 if is_muted else -18.0
|
|
|
|
if has_node("MeshInstance3D"):
|
|
var mesh_instance = get_node("MeshInstance3D")
|
|
var material = StandardMaterial3D.new()
|
|
material.albedo_color = Color.RED if is_muted else Color.GREEN
|
|
mesh_instance.material_override = material
|