#I need help with sounds
1 messages · Page 1 of 1 (latest)
What's the problem? It just doesn't play the sound?
How are you playing the sound - autoplay? Or through code?
trough code. in the ready loop i start playing it, then in another loop i just set it to be playing or not.
Mind sharing?
using Godot;
using System;
public partial class SPAnimator : Node3D
{
AnimationPlayer ap;
[Export] Node3D[] lights;
RandomNumberGenerator rand = new RandomNumberGenerator();
float counter;
float rid;
bool swich;
bool lightSwitch;
bool prevLightSwitch;
public override void _Ready()
{
ap = (AnimationPlayer)GetChild(0);
rand.InitRef();
rid = rand.RandfRange(0.2f, 5);
((AudioStreamPlayer3D)lights[0]).Play();
}
public override void _Process(double delta)
{
base._Process(delta);
if (!ap.IsPlaying())
swich = !swich;
if (!swich) ap.Play("Sway-loop");
else ap.PlayBackwards("Sway-loop");
if(counter >= rid || counter >= 5)
{
counter = 0;
rid = rand.RandfRange(0.2f, 5);
lightSwitch = !lightSwitch;
}
else counter += (float)delta;
if(lightSwitch != prevLightSwitch)
{
((AudioStreamPlayer3D)lights[0]).Playing = lightSwitch;
for (int i = 1; i < lights.Length; i++)
lights[i].Visible = lightSwitch;
}
prevLightSwitch = lightSwitch;
}
}
in code lights[0] is the audioPlayer
Thank you, and to clarify, the problem is that the sound doesn't play at all?
yes. when in play mode.
If the AudioStreamPlayer3D node is not visible in the scene tree, it won't play. I wonder if that could be what's happening.
if i play the sound in the inspector is works
I see that you have added it to the lights array
so maybe its Visible property gets set false
ok. ill check that.
no dice.