Files
grass-cutters/Assets/Scripts/World/BeltSound.cs
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

43 lines
1.4 KiB
C#

using UnityEngine;
namespace GrassCutter
{
/// <summary>One sound for all the belts: it stands on the nearest belt with something riding on it.</summary>
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);
}
}
}