Audio issues.. please help! :)

So I am starting to add some audio to my game, but I am getting some weird results. I have a tree with an audio source, in the audio clip I have an attached clip called tree fall. Now I also have a script on the tree that calls audio.PlayOneShot(treeFall, 1); and in the inspector I have dragged the audioclip into a public variable called treeFall.

Now the clip plays fine but it sounds TERRIBLE. I dont even know what to call it, maybe its playing way to fast, I am just not sure but wow its bad.

The sound file is an MP3.

So questions:

I assume MP3 is fine to use?
Do I need to attach the sound to both the audio clip in the audio source component and also call in via a script and public variable? Or would doing this duplicate my sound file maybe?

Thanks much for any help!!

here is a snipit of code:

					if(Input.GetButtonDown("Fire Weapon"))
					{
						startTime = Time.time;
					}
					if(Input.GetButton("Fire Weapon"))
					{
						if(!audio.isPlaying)
						{
						audio.PlayOneShot(chopTree, 1);
						}

OK, I see the problem. What’s happening is audio.PlayOneShot creates an instance much like PlayClipAtPoint, a separate gameObject that plays the audio then destroys itself. So when you ask if(!audio.isPlaying) it will always return false, as that object is not playing sound, a different object is. Simply use audio.Play() , and make sure the Loop box is also unchecked =]


Sure =]

Here are the Unity Scripting References :

I have several answers I could also link, but for now I think this one will explain how to assign an audioClip in script, change audio clips and check if they are already playing :

(I’m Jay Kay / alucardj)

It might be because it is a 3D sound. This can cause the sound to have a weird doppler effect. Try changing the Sound file in Unity to not be a 3D Sound via the Inspector.

EDIT: You might want to try audio.PlayOneShot then, as that only plays the sound once.

Thanks this answer was very helpfull for me. Problem solved :slight_smile:

OK, I see the problem. What’s
happening is audio.PlayOneShot creates
an instance much like PlayClipAtPoint,
a separate gameObject that plays the
audio then destroys itself. So when
you ask if(!audio.isPlaying) it will
always return false, as that object is
not playing sound, a different object
is. Simply use audio.Play() , and make
sure the Loop box is also unchecked =]