xiandie/config/audio/random_audio_stream_player.gd

23 lines
544 B
GDScript3
Raw Permalink Normal View History

2024-12-23 01:30:31 +00:00
extends AudioStreamPlayer
class_name RandomAudioStreamPlayer
@export var audio_collections: Array[AudioStreamCollection] = []
2024-12-23 01:30:31 +00:00
func _init() -> void:
bus = "game_sfx"
2024-12-23 01:30:31 +00:00
func play_random():
if audio_collections == null:
push_warning("empty audio_collections")
2024-12-23 01:30:31 +00:00
return
var audio_collection := audio_collections.pick_random() as AudioStreamCollection
2024-12-23 01:30:31 +00:00
stream = audio_collection.audios.pick_random()
if stream == null:
push_error("empty stream in audio_collection", audio_collection)
return
# pitch_scale = randf_range(.8, 1)
2024-12-23 01:30:31 +00:00
play()