Add an audio listener to your camera (it should be there by default already):

AudioManager

Audio Manager provides a long term solution for managing audio clips in a big project. You can also re-use this manager in every future gamedev project. So let’s get to it:

using System;
using System.Linq;
using UnityEngine;


public class AudioManager : MonoBehaviour
{
public Sound[] sounds;

public static AudioManager instance;
void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
return;
}
// lives through transitioning
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;
}
}

void Start()
{
Play("bg_music");
}
public void Play(string name)
{
Sound snd = Array.Find(sounds, sound => sound.name == name);
try
{
snd.source.Play();
}
catch (Exception e)
{
Debug.LogWarning("sound not found");
}


}
}
using UnityEngine.Audio;
using UnityEngine;

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

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

public bool loop;

[HideInInspector] public AudioSource source;
}
holdsObject = true;
FindObjectOfType<AudioManager>().Play("telekinesis_pickup");

INTP, Master’s degree in comp-sci, Creator, indie game developer, director, writer, photographer. I like BJJ, Jungian psychology, mythology and memes.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store