extends OmniLight3D # Audio-Parameter @export var audio_player: AudioStreamPlayer3D @export var energy_multiplier: float = 10.0 @export var base_energy: float = 1.0 @export var use_audio: bool = true # Toggle für Audio-Reaktion # Blink/Farb-Parameter @export var blink_speed: float = 16.0 @export var colors: Array[Color] = [Color.RED, Color.BLUE, Color.GREEN] @export var audio_driven_colors: bool = false # Farben durch Audio steuern var time: float = 0.0 var spectrum: AudioEffectSpectrumAnalyzerInstance func _ready(): # Setup Spectrum Analyzer wenn Audio-Player vorhanden if audio_player: var bus_idx = AudioServer.get_bus_index("Master") # Prüfe ob bereits ein Spectrum Analyzer existiert if AudioServer.get_bus_effect_count(bus_idx) == 0: var effect = AudioEffectSpectrumAnalyzer.new() AudioServer.add_bus_effect(bus_idx, effect) spectrum = AudioServer.get_bus_effect_instance(bus_idx, 0) func _process(delta): time += delta var audio_energy = 0.0 # Audio-Analyse if use_audio and audio_player and audio_player.playing and spectrum: var magnitude = spectrum.get_magnitude_for_frequency_range(20, 20000) audio_energy = magnitude.length() # Licht-Energie wird von Audio gesteuert light_energy = base_energy + (audio_energy * energy_multiplier) else: # Fallback zum ursprünglichen Pulsieren var pulse = (sin(time * blink_speed) + 1.0) / 2.0 light_energy = pulse * 3.0 # Farbwechsel if audio_driven_colors and audio_energy > 0.1: # Farbe wechselt bei starkem Audio-Signal var color_index = int(audio_energy * 100) % colors.size() light_color = colors[color_index] else: # Ursprünglicher zeit-basierter Farbwechsel var color_index = int(time * 2) % colors.size() light_color = colors[color_index]