Audio doesn't work without play on awake ticked

Hi, I have been through most of the FPS tutorial, well the bits that applied to me. I am now trying to put these into my game but have been struggling with a couple of issues that didn't occur in the tutorial.

One of these things is that for my guns' audio to work, the "play on awake" button needs to be ticked. When it is, the audio plays fine when I fire, but obviously plays initially when I start. If I untick it it doesn't play at the start, but it doesn't play when I fire either.

Another thing is that my rocket sound, which is attached to the rocket, seems to cut out after a second or two, and I would like the audio to last longer as the clip is about 5 seconds. I can't see where I can do this...

Thanks!

You don’t have to check “Play on Awake”, just use AudioSource.enabled property: put a line “audio.enabled = true;” before “audio.Play();” when triggering your machine gun sound.

You can fiddle the result by setting volume to 0 initially so that you don't hear the sound and then turning it back up afterwards. Without seeing how you've implemented sounds I can't say why it's happening. You can try stripping all the sound scripts from your game and then implement your own basic version, a simple play on mouse click and build up from there.

Here's what I did and it works. You hierarchy should have an empty Mavhinegun game object with a machinegun script along with the muzzle_flash game object dropped into the variable.(You will have to make sure you drop the muzzle_flash into the empty game object Machinegun script so the muzzle_flash will work) But you don't have the actual machinegun yet so you can't drag anything yet. Just remeber to do it. Now grab your machine gun prefab from the weapons file in your project window. Drag it up and drop it into the empty machinegun to make it the child object of the empty Machinegun game object. The ACTUAL machinegun game object when you created it will have the muzzle_flash attached to it as a child of the machinegun. Now add another machinegunscript to the ACTUAL machinegun game object. Now add an "audio source"(componets/audio/audio source) to the ACTUAL machinegun game object. "UNMARK" the "Play on Awake" button but keep the "LOOP" MARKED> This script will have a muzzle_flash variable slot which you are going to drag and drop your Sparks prefab into.(Remember it's the empty machinegun game object in your Hierarchy that controls the muzzle_flash not the actual machinegun.) Go to MIsc file folder in your Project view and find the sparks prefab. NOW! Add an audio source to the Sparks prefab. And this time you will leave the "Play On Awake" MARKED! MARK the LOOP also! Now drag the Sparks prefab with the audio source into- Guess? This took me awhile to figure out. Drag it into the muzzle_flash variable in the actual machinegun game object script. So what you should have in your Hierarchy is two machinegun scripts and and two audio sources. The two machinegun scripts will each have a muzzle_flash variable. The top will have the muzzle_flash and the lower one will have the Sparks. The two audio sources will have the "Play on Awake" UNMARKED in the ACTUAL machinegun and the MARKED on the muzzle_flash variable(Sparks)