33 lines
845 B
GDScript
33 lines
845 B
GDScript
extends Node2D
|
|
class_name PlayerAudio
|
|
|
|
|
|
@onready var jump : AudioStreamPlayer = $Jump
|
|
@onready var shoot : AudioStreamPlayer = $Shoot
|
|
@onready var run : AudioStreamPlayer = $Run
|
|
@onready var slide : AudioStreamPlayer = $Slide
|
|
|
|
@export var mute : bool = false
|
|
|
|
@onready var sound_names : Dictionary = {"jump": jump, "shoot":shoot, "run":run, "slide":slide}
|
|
|
|
func play_sound(sound_name: String) -> void:
|
|
if not mute:
|
|
if sound_names.has(sound_name):
|
|
#print(shoot)
|
|
#print(sound_names["shoot"])
|
|
#print(sound_names[sound_name])
|
|
#print(sound_name)
|
|
sound_names[sound_name].play()
|
|
|
|
|
|
func is_playing(sound_name: String)->bool:
|
|
if sound_names.has(sound_name):
|
|
return sound_names[sound_name].playing
|
|
return false
|
|
|
|
|
|
func stop_sound(sound_name: String) -> void:
|
|
if sound_names.has(sound_name):
|
|
sound_names[sound_name].stop()
|