- Home /
[Solved]Cant play AudioClips in AudioSource
Hello Guys, I dont know what i'm doing wrong, cant see any abnormal situation but unity cant play my audioclips in audiosource,
Note: sorry about my variable names ;)
I have 3 audioclips, 0,1,2.
first i added public variables ;
public AudioClip[] sounds;
public AudioSource audiomama;
byte mamasound = 0 //witch audioclip will play
then in start func;
void Start ()
{
mamasound = 0;
audiomama = GetComponent<AudioSource> ();
}
okay, simply 0 is engine starting, 1 idle, 2 shutdown.
I have an IEnumerator which playing my sounds correctly in loop.
IEnumerator PlaySound (byte mam)
{
audiomama.clip = sounds [mam];
audiomama.Play ();
yield return new WaitForSeconds (audiomama.clip.length);
}
Okay now in Update Function, when player press arrow keys, move and play sound;
void Update ()
{
if (Input.GetKeyDown (KeyCode.LeftArrow) == true || Input.GetKeyDown (KeyCode.RightArrow) == true) {
//moving code deleted
if (mamasound == 0) {
PlaySound (0);
mamasound = 1;
}
if (mamasound == 1) {
PlaySound (1);
}
}
if (Input.GetKeyUp (KeyCode.RightArrow) == true || Input.GetKeyUp (KeyCode.LeftArrow) == true) {
PlaySound (2);
mamasound = 0;
}
}
Note: I have selected my AudioClips in UnityEditor, I have an audiosource attached in my gameObject... and an AudioListener in my mainCamera...
Here is a screenshot of my attached script;
Can you help me please, I can't find any solution...
Thank you!
Are you sure that they sounds aren't playing but the inspector is not being updated and the sounds are not audible (as they would be if they are 3D and the main camera is too far away)?
Can you hear the sounds if you change the listener to the gameobject with the audiosource and change the sounds from 3d to 2d sounds?
Thank you for your answer but unforcunately.... I tryed 3d and 2d, I have increased my max distance... but nothing... am i deaf or what...
Answer by TwinPrime · May 24, 2015 at 04:07 PM
Okay,problem solved...
fix;
StartCoroutine (PlaySound (0));
instead of
PlaySound (0);
yeah... well.. uhm.. -.-
Your answer
Follow this Question
Related Questions
Audio loops too early 2 Answers
No overlapping sounds 0 Answers
detect audio then record and then play 0 Answers
Audio clip not playing 1 Answer
WWW Audio and PlayOneShot: Playing the same AudioClip Twice Cuts off First Instance 1 Answer