-
Notifications
You must be signed in to change notification settings - Fork 1
/
HSliders.gd
54 lines (33 loc) · 1.45 KB
/
HSliders.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extends Node
# The code for volume sliders to work.
# For simplicity's sake, I have put the sliders in a VBox Container, but you can make them a seperate scene if you want.
# IMPORTANT: Remember to check out Global.gd
# REMEMBER: THE AUDIO YOU CHOOSE SHOULD BE IN A SPECIFIC AUDIO BUS TO WORK.
# You MUST put this one on the _ready(): script
func _ready():
$VBoxContainer/MusicVolume.value = Global.volume1
$VBoxContainer/FXVolume.value = Global.volume2
# First, let's create a signal via the Node tab on your Node's properties.
func _on_Music_Volume_value_changed(value):
# Then, let's get the volume of our audio bus.
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index("music"),
linear2db(value)
)
# After we do that, we assign the slider"s value to the Global variable.
Global.volume1 = $VBoxContainer/MusicVolume.value
# Why do that? Because we don't want the value to reset everytime we switch from one scene to another.
# Now let's do the same thing with our FX Slider.
func _on_FX_Volume_value_changed(value):
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index("FX"),
linear2db(value)
)
Global.volume2 = $VBoxContainer/FXVolume.value
# And you're done!
# Extra button to test the FX Volume. You can delete it if you want.
func _on_TestFXButton_pressed():
$TestFX.play()
# Button for test scene. Ignore completely if you only care about the source.
func _on_Button_pressed():
get_tree().change_scene("res://Scene.tscn")