I have the following function, which, upon executing, is supposed to change the stream every time the rng gets a certain number
func Footsteps4(sample1, sample2, sample3, sample4): #Footsteps function for 4 samples
print("called")
var random_number = rng.randi_range(0, 4)
match str(random_number): #Match the result of the rng as a string (text) - the result must be stored as a variable
"0":
if AudioPlayer.is_playing() == false: #So it doesn't changes stream mid playing
AudioPlayer.stream = sample1
"1":
if AudioPlayer.is_playing() == false: #So it doesn't changes stream mid playing
AudioPlayer.stream = sample2
"2":
if AudioPlayer.is_playing() == false: #So it doesn't changes stream mid playing
AudioPlayer.stream = sample3
"3":
if AudioPlayer.is_playing() == false: #So it doesn't changes stream mid playing
AudioPlayer.stream = sample4
if AudioPlayer.is_playing() == false:
AudioPlayer.play()
func _physics_process(delta):
var obj = floor_raycast.get_collider()
if floor_raycast.is_colliding() == true and $"../FloorRayCast".is_colliding() == true:
if Input.is_action_pressed("move_forward"):
Footsteps4(PWalking1, Pwalking2, Pwalking3, Pwalking4)
The stream changes correctly, but the problem is that it changes once I release and press "move_forward"
, when I actually want it to change after the previous audio stream has finished.
What I want to do is change the stream every time one audio finishes, so the same stream isn't repeated all the time. What am I doing wrong?