- Home /
Problem with audio
I have a GameObject to which I attached an Audio Source Component. In the script attached to the GameObject I wanted to add the following lines:
public AudioClip[] sound;
public void play_sound(int n){
audio.clip = sound[n];
audio.Play()
}
So whenever I want to play a sound I just call the play_sound
function. Problem is that audio is not seen in the function for some reason. Why is this happening?
I would greatly appreciate if you replied to me in any way :)
I posted an answer and you probably have read it (said that you were online 3 hours ago). If you found it helpful, please add it as the "best answer" or whatever or if it didn't help let me know more. If you are expecting answers on your questions, this is the way to go :) (more people will want to help you)
Answer by Ruben_Chris · Jul 31, 2016 at 08:48 PM
The "audio" variable has been deprecated. Replace every "audio" with GetComponent <AudioSource>()
to fix your error.