How can I play two different audio clips in Unity depended on the code behind? Into my object I've added two audio sources namely 'Player GunShot' and 'outOfAmmo'.
Into the same object I've also added a C# script whit this code:
public currentBullets = 1; private AudioSource gunAudio; private AudioSource outOfAmmo; void Awake() { gunAudio = GetComponent<AudioSource>(); outOfAmmo = GetComponent<AudioSource>(); } void Update() { if (currentBullets == 0) { outOfAmmo.Play(); } else { gunAudio.Play(); } } Can this code give any problems because in the Awake methode? I've not defined with audio source the variable must be. So which source go he take to play?
