AudioClip, AudioSource... Help

Hi there. I’m still learning Unity, and I’m trying to make my balloon pop when touched. I’ve managed it, but I’m confused. I did it with the help of AI, and the end result seems weird to me.

I did an AudioManager script singleton :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{

    public static AudioManager Instance;
    [SerializeField] private AudioClip pop;



    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
        DontDestroyOnLoad(gameObject);

      
    }
    
    public void popSound()
    {
        AudioSource audioSource = GetComponent<AudioSource>();
        audioSource.PlayOneShot(pop);

    }

}

And therefore in my game I have this object :

There’s the audioClip in the script, and an audiosource component…
It seems really redondant, I’m sure there is a better way to do this ?

Thanks a lot !

Edit : I got rid of the Audioclip entirely, and just do audioSource.Play(); in the method now. It works, but are we forced to add an AudioSource component in the object for each individual sound ? I thought we could put lots of audioclips in the script and deal with sound this way. I really don’t know what’s the norm ?

You can play the sound from your balloon’s script without the need for an AudioSource component.

    public AudioClip clip;

    void OnCollisionEnter()
    {
        AudioSource.PlayClipAtPoint(clip, transform.position);
        Destroy(gameObject);
    }

Doing it this way means that when the balloon is destroyed the sound will still continue to play until it has finished.

or try this:

public class AudioManager : MonoBehaviour
{
    public static AudioManager Instance;
    private AudioSource audioSource;

    [SerializeField] private AudioClip pop;
    // Add more clips here as needed, like jump, shoot, etc.

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
            audioSource = GetComponent<AudioSource>();  // Get the one source in AudioManager
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public void PlaySound(AudioClip clip)
    {
        audioSource.PlayOneShot(clip);  // Play any clip passed to this method
    }

    public void PopSound() 
    {
        PlaySound(pop);  // Call specific sounds if needed
    }
}

With this setup, you only need one AudioSource in your AudioManager, and you can play whatever sound by calling PlaySound() and passing the clip. Add all your clips in the AudioManager script, and trigger them from anywhere.