20 lines
634 B
GDScript3
20 lines
634 B
GDScript3
|
extends Button
|
||
|
|
||
|
class_name SoundButton
|
||
|
|
||
|
@export var audio_collections: Array[AudioStreamCollection]
|
||
|
|
||
|
func _ready():
|
||
|
if !audio_collections:
|
||
|
audio_collections.append(preload("res://config/audio/ui/ui_click.tres"))
|
||
|
#print("sound button loaded default ui_click.tres")
|
||
|
|
||
|
if audio_collections:
|
||
|
#print("sound button load audio_collections into audio_player")
|
||
|
var audio_player := RandomAudioStreamPlayer.new()
|
||
|
audio_player.audio_collections = audio_collections
|
||
|
pressed.connect(audio_player.play_random)
|
||
|
add_child(audio_player)
|
||
|
else:
|
||
|
printerr("sound button has no audio_collections! ignore initialization of audio_player")
|