@@ -39,8 +39,7 @@ enum ControllerMode { OnOff, On, Off }
3939 if pushed :
4040 _target_mesh_rotation = x
4141@export var speed = 10.0
42- @export var sound_on :AudioStream
43- @export var sound_off :AudioStream
42+ @export var sound_event = "cabin_button"
4443@export var sound_max_distance :float = 3.0 :
4544 set (x ):
4645 sound_max_distance = x
@@ -59,17 +58,24 @@ var _t:float = 0.0
5958
6059var _enabled :bool = true
6160var _setup_phase :bool = true
62- var _sound :AudioStreamPlayer3D = AudioStreamPlayer3D .new ()
61+ var _sound :SfxPlayer3D = SfxPlayer3D .new ()
6362
6463func _ready ():
65- add_child (_sound )
6664 _sound .max_distance = sound_max_distance
65+ _sound .max_tracks = 2
66+ var cabin = get_cabin ()
67+ if cabin :
68+ _sound .bank = cabin .sound_bank
6769 connect ("pushed_changed" , self ._on_pushed_changed )
6870 controller_changed .connect (_update_state )
6971 Console .console_toggled .connect (_on_console_toggled )
7072
7173func _enter_tree ():
7274 _setup_phase = true
75+ add_child (_sound )
76+
77+ func _exit_tree () -> void :
78+ remove_child (_sound )
7379
7480func _on_console_toggled (visible :bool ):
7581 _enabled = not visible
@@ -124,9 +130,10 @@ func _process_tool(delta):
124130 _mesh .position = _mesh_original_position + _current_position
125131
126132func _play_sound ():
127- _sound .stream = sound_on if pushed else sound_off
128- if _sound .stream :
129- _sound .play ()
133+ if pushed :
134+ _sound .play (sound_event )
135+ else :
136+ _sound .stop (sound_event )
130137
131138func _on_pushed_changed ():
132139 if pushed :
0 commit comments