Files
project-thought-experiment/scripts/sound_effect.gd
2024-01-26 18:28:18 +01:00

15 lines
418 B
GDScript

extends AudioStreamPlayer
class_name SoundEffect
@export var audio_library: Array[SoundeffectResource]
@export_range(0,2) var pitch_variation: float
func play_key(key: String) -> void:
for res in audio_library:
if res.key == key:
stream = res.audio
pitch_scale = 1 + randf_range(pitch_variation * -1, pitch_variation)
play()
return
push_error(key + " is not available in the Audio Library variable")