Skip to content

Commit

Permalink
Mute soda can spray in splitscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Sep 29, 2024
1 parent affb21f commit 2b4574f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Assets/Audio/Props/SodaCan.asset
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ MonoBehaviour:
min: 0.9469697
max: 1
is3D: 1
shouldPlayInSplitscreen: 0
13 changes: 11 additions & 2 deletions Assets/Scripts/Audio/AudioGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AudioGroup : ScriptableObject

[SerializeField]
private AudioClip[] sounds;

#if UNITY_EDITOR
[MinMax(-10, 10), ContextMenuItem("Preview/Low Pitch", "PreviewLowPitch"), ContextMenuItem("Preview/High Pitch", "PreviewHighPitch")]
#endif
Expand All @@ -30,6 +30,9 @@ public class AudioGroup : ScriptableObject
[SerializeField]
private bool is3D = true;

[SerializeField]
private bool shouldPlayInSplitscreen = true;

private void Modulate(AudioSource source)
{
// Range has override for ints, so we need to force the endpoints to be floats in order to achieve a continuous scale.
Expand All @@ -50,19 +53,25 @@ private void Modulate(AudioSource source)
public void Play(AudioSource source)
{
Modulate(source);
if (!shouldPlayInSplitscreen && source.spatialBlend == 0)
return;
source.PlayOneShot(sounds.RandomElement());
}

public void PlayExclusively(AudioSource source)
{
Modulate(source);
if (!shouldPlayInSplitscreen && source.spatialBlend == 0)
return;
source.clip = sounds.RandomElement();
source.Play();
}

public void PlayDelayed(AudioSource source, float delay)
{
Modulate(source);
if (!shouldPlayInSplitscreen && source.spatialBlend == 0)
return;
source.clip = sounds.RandomElement();
source.PlayDelayed(delay);
}
Expand Down

0 comments on commit 2b4574f

Please sign in to comment.