Skip to content

Commit

Permalink
Enable 3D sound when only one local player
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed May 31, 2024
1 parent 4d081e6 commit fa990f3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Assets/Scripts/Audio/AudioGroup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using CollectionExtensions;
using System.Linq;
using CollectionExtensions;
using UnityEngine;
using UnityEngine.SceneManagement;

[CreateAssetMenu(fileName = "AudioGroup", menuName = "Audio/New Audio Group")]
public class AudioGroup : ScriptableObject
Expand Down Expand Up @@ -30,6 +32,13 @@ private void Modulate(AudioSource source)
var pitch = continuousPitchBend ? Random.Range((float)semitoneRange.Min, (float)semitoneRange.Max) : Random.Range(semitoneRange.Min, semitoneRange.Max);
source.pitch = Mathf.Pow(SEMITONE_PITCH_CONVERSION_UNIT, pitch);
source.volume = Random.Range(volumeRange.Min, volumeRange.Max);

// Use 3D sound if there's only one local player,
// otherwise we're in splitscreen and should not spatialize sounds.
var isOnlyOneLocalPlayer = PlayerInputManagerController.Singleton.LocalPlayerInputs.Count == 1;
// TODO replace this check!
var isInArena = Scenes.NotArenaScenes.Contains(SceneManager.GetActiveScene().name);
source.spatialBlend = isOnlyOneLocalPlayer && isInArena ? 0 : 1;
}

public void Play(AudioSource source)
Expand Down

0 comments on commit fa990f3

Please sign in to comment.