#3d sound isn't working.

2 messages · Page 1 of 1 (latest)

zealous egret
#

I posted on this issue a few days ago and i still dont know why it doesnt work. i have a neon light sound that should play when the light is on, but i just cant hear it working. ill post the code and a small video with the issue.

#
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()
    {
        lights[0].Visible = true;
        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;

        lights[0].Visible = true;

        if (lightSwitch != prevLightSwitch)
        {
            ((AudioStreamPlayer3D)lights[0]).Playing = lightSwitch;

            for (int i = 1;  i < lights.Length; i++)
                lights[i].Visible = lightSwitch;
        }

        prevLightSwitch = lightSwitch;
    }
}