- Home /
Car Tutorial #1 - Sound Broken
Hi, I'm a beginner making my way through my first tutorial. I'm a Mechanical Engineer with experience in Matlab, VB.net (mainly visual basic, but some C), and a number of proprietary scripting languages. So far Unity looks a lot like the vb.net framework, so that's nice.
I have just completed part 1 of the car tutorial and most everything seems to work - there are skid marks, lighting seems on, etc. The problem is some of the sounds don't work. I double/triple checked all the settings and also checked the files to make sure that they are running. The only odd think I noticed is that some of the sound files were mistyped with "can" instead of car, but that should affect anything. I even tried a "build ad run" to make sure it wasn't a problem with the editor mode, but the sound also has trouble there. The sounds that do work include the crash and initial door slam. The theme song and engine sounds do not work.
There are no console errors.
I tried putting in a Debug.log check inside of the functions for the engine and theme song and both logs show up (theme song just shows up at initialization of game and engine log repeats.
Any ideas? Thanks for helping out a newbie! =)
Actually I figured this out with the help of http://forum.unity3d.com/threads/126188-Sound-problem-with-Car-Tutorial-in-Unity-3.5?p=850067
The problem is that the .playOnAwake = true statements are being executed inside the Awake() function, which makes little sense. In order to get it to work, just remove the .playOnAwake = true statements, and add simple .Play() calls once the settings are configured - i.e. the last statement for that audio object. For example:
function Awake() { car = transform.GetComponent(Car);
DVolume *= 0.4;
EVolume *= 0.4;
FVolume *= 0.4;
$$anonymous$$Volume *= 0.7;
LVolume *= 0.4;
windVolume *= 0.4;
DAudio = gameObject.AddComponent(AudioSource);
DAudio.loop = true;
//DAudio.playOnAwake = true;
DAudio.clip = D;
DAudio.volume = DVolume;
DAudio.Play();
If you have something more complex going on, you may want to check if the audio is already playing:
if (!DAudio.isPlaying()) { DAudio.Play(); }
Answer by Meltdown · Mar 08, 2012 at 08:36 AM
This is an issue since 3.5 was released. In fact Unity has decided that this is going to be expected behaviour from now on.
Simply do the following check..
if(!DAudio.isPlaying)
DAudio.Play();
Your answer
![](https://koobas.hobune.stream/wayback/20220613064903im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity5 Vehicles package sound problem 0 Answers
Car audio script 0 Answers
How to i make a gear system from this script? help please 1 Answer
audio fades 0 Answers
Buggy Engine Sound (pitch) 0 Answers