using UnityEngine; namespace GrassCutter { /// One sound for all the belts: it stands on the nearest belt with something riding on it. public class BeltSound : MonoBehaviour { const float Hear = 14f, Every = 0.25f, Loud = 0.3f; AudioSource _loop; float _next, _want; void Update() { if (!_loop) { if (!AssetBank.I) return; _loop = Sfx.Loop("conveyor_loop", transform, 0f); if (!_loop) { enabled = false; return; } } if (Time.time >= _next) { _next = Time.time + Every; var cam = CameraFx.Cam; float best = Hear * Hear; _want = 0f; if (cam) foreach (var c in Conveyor.All) { if (!c || c.Count == 0) continue; var p = c.NearestPoint(cam.transform.position); float d = (p - cam.transform.position).sqrMagnitude; if (d >= best) continue; best = d; transform.position = p; _want = Loud; } } _loop.volume = Mathf.MoveTowards(_loop.volume, _want * Sfx.SfxVolume, Time.deltaTime * 0.8f); } } }