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 ?
