void Update() { DepthSound depthSound = config.GetAvailableDepthSound(GameManager.main.PlayerDepth); if (depthSound == null) { return; } depthSound.Timer += Time.deltaTime; if (depthSound.Timer > depthSound.Interval) { float rng = Random.Range(0f, 1.0f); if (rng <= depthSound.Chance) { if (depthSound.Clips.Count > 0) { AudioClip clip = depthSound.Clips[Random.Range(0, depthSound.Clips.Count)]; if (clip != null) { PlayClip(clip); Debug.Log($"played {clip} for depth range {depthSound.DepthMin} - {depthSound.DepthMax} ({rng * 100.0f}% -> {depthSound.Chance * 100.0f}%)"); } } } else { Debug.Log($"Rng was {rng * 100} and chance is {depthSound.Chance * 100}"); } depthSound.Timer = 0f; depthSound.PlayedPreviously = Time.time; } }
public DepthSound GetAvailableDepthSound(float depth) { DepthSound depthSound = depthSounds.Where( sound => depth > sound.DepthMin && depth < sound.DepthMax ).FirstOrDefault(); return(depthSound); }