x


How do I get the Sound to play every instance?

Right now, I have a custom sound clip that has a longer duration than that of the standard clip that came with the machine gun in the FPS demo. How do I make it loop on top of itself or make it play at every firing? Right now it waits for the sound file to finish before starting the next one. Here's the section of the script.

function LateUpdate() { if (muzzleFlash) { // We shot this frame, enable the muzzle flash if (m_LastFrameShot == Time.frameCount) { muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward); muzzleFlash.enabled = true;

		if (audio) {
			if (!audio.isPlaying)
				audio.Play();
			audio.loop = true;
		}
	} else {
	// We didn't, disable the muzzle flash
		muzzleFlash.enabled = false;
		enabled = false;

		// Play sound
		if (audio)
		{
			audio.loop = false;
		}
	}
}

}

more ▼

asked Feb 02 '10 at 08:29 PM

Envy gravatar image

Envy
165 17 18 22

Could you paste the portion of the code from the FPS demo which handles the firing? (haven't looked over it closely myself)

Feb 02 '10 at 10:06 PM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can dynamically create and add a new audio source component and have it play the sound file and then once the sound finishes playing destroy that component.

more ▼

answered Feb 02 '10 at 09:29 PM

equalsequals gravatar image

equalsequals
4.5k 16 28 64

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1027

asked: Feb 02 '10 at 08:29 PM

Seen: 1368 times

Last Updated: Feb 02 '10 at 11:28 PM