Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Audio Manager

A Config Script for Baldi's Basics

No ads for members. Membership is 100% free. Sign up!
101 2 kb Raw Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using UnityEngine.Audio;
using UnityEngine;

public class AudioManagerScript : MonoBehaviour
{
  public Sound[] sounds;
  public static AudioManager instance;
  void Awake()
  {
     if (instance == null)
     {
       instance = this;
     }
     else
     {
        Destroy(gameObject);
     }

DontDestroyOnLoad(gameObject);
    foreach (Sound sound in sounds)
    {
      sound.source = gameObject.AddComponent<AudioSource>();
      sound.source.clip = sound.clip;
      sound.source.volume = sound.volume;
      sound.source.pitch = sound.pitch;
      sound.source.loop = sound.loop;
      sound.source.spatialBlend = sound.spatialBlend;
     
    }
  }
  public void Play(string soundName)
  {
    Sound sound = Array.Find(sounds, sound => sound.name == soundName);
    if (sound == null)
    {
      return;
    }
    sound.source.Play();
  }
  public void DisableSFX()
  {
    Sound[] sfxSounds = Array.FindAll(sounds, sound => sound.isSFX)
    for (int i = 0; i < sfxSounds.Length; i++)
    {
      sfxSounds[i].source.Stop();
      sfxSounds[i].source.Pause();
    }
  }
  public void EnableSFX()
  {
    Sound[] sfxSounds = Array.FindAll(sounds, sound => sound.isSFX)
    for (int i = 0; i < sfxSounds.Length; i++)
    {
      sfxSounds[i].source.UnPause();
    }
  }
  public void DisableThemes()
  {
    Sound[] themes = Array.FindAll(sounds, sound => sound.isTheme)
    for (int i = 0; i < themes.Length; i++)
    {
      themes[i].source.Pause();
    }
  }
  public void EnableThemes()
  {
    Sound[] themes = Array.FindAll(sounds, sound => sound.isSFX)
    for (int i = 0; i < themes.Length; i++)
    {
      themes[i].source.UnPause();
    }
  }
}
____________________________
using UnityEngine.Audio;
using UnityEngine;

[System.Serializable]
public class Sound
{
  public string name;
  public AudioClip clip;

  [Range(0f, 1f)]
  public float volume;

  [Range(0f, 1f)]
  public float pitch;
  public bool loop;

  [Range(0f, 1f)]
  public float spatialBlend;

  [HideInInspector]
  public AudioSource source;

  public bool isSFX;

  public bool isTheme;
}

Updates

Toggle Themes & SFX 5d
  • Addition Added support for toggling themes & sfx by simply checking of if the sound is a theme or a sfx
  • Improvement Fixed any coding errors found
Audio manager for simply playing audio.

*note
Don't just copy paste the code, there are 2 classes because they're 2 seperate scripts
and also this is a script for you to custom specific values for sounds (like volume, pitch etc.) In the editor. Also make sure you set this as a prefab also
Sign up to access this!

No comments yet

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Key Authors
Brackeys
Creator
RealT5mpler
RealT5mpler Joined 11mo ago
Offline
416 points Ranked 49057th
16 medals 4 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • Submitted 15 Tutorials Medal icon
  • 50 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
Distributor

Submitter

RealT5mpler avatar
RealT5mpler Joined 11mo ago
Not on right ok
416 points Ranked 49057th
16 medals 4 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • Submitted 15 Tutorials Medal icon
  • 50 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
RealT5mpler
Redistributor
Are you the owner? Request Ownership
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

License

Attributes

Language
CSS

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • 1
  • 223
  • 15d
  • 4d
  • 5d

More from Submitter

WiPs by Submitter

More Other/Misc Scripts