Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Entity2020 studios |
I’ve just switched to version 4.0.2 of Godot, and I’m trying to program a radio within my game, that allows you to change what song is playing. But it only plays one song.
I’ve tested it, and it seems like it’s trying to change something, but it isn’t succeeding. This is the code I’ve used:
var MusicChoice1 = preload("res://Music and Audio/Lucid Mind OST/Siesta.ogg")
var MusicChoice2 = preload("res://Music and Audio/Lucid Mind OST/Anthropology.ogg")
var ChosenSong = 0
@warning_ignore("unused_parameter")
func _process(delta):
ChosenSong = MusicChoice1
if !$AudioStreamPlayer3D.is_playing():
$AudioStreamPlayer3D.stream = ChosenSong
if Input.is_action_pressed("Interact"):
if ChosenSong == MusicChoice1:
$AudioStreamPlayer3D.stop()
ChosenSong = MusicChoice2
$AudioStreamPlayer3D.play()
if ChosenSong == MusicChoice2:
$AudioStreamPlayer3D.stop()
ChosenSong = MusicChoice1
$AudioStreamPlayer3D.play()
Is there a way to fix this issue?
To be exact, when I interact with the radio in my game, it restarts the song that’s playing.
Entity2020 studios | 2023-04-30 10:24