#3d sound isn't working.
2 messages · Page 1 of 1 (latest)
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;
}
}