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

102 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
102
using System;
using UnityEngine.Audio;
using UnityEngine;

public class AudioManagerScript : MonoBehaviour
{
    public Sound[] sounds;
    public static AudioManagerScript 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, theSound => theSound.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

Final Release I think 1y
  • Improvement Fixed all coding errors, it should work now
Toggle Themes & SFX 1y Addition Improvement
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

No comments yet