Just recently started in Unity and I recently updated to 3.5 from 3.4. I played the car tutorial and noticed that there is no sound (except for crashes). I tried it on another computer with 3.5 and my freinds computer who also has 3.5 and had the same result. Has anyone else encountered this problem? Is there any way to solve it?
The AudioSource.playOnAwake method is not very intuitive (originally it was intended for the editor inspector only), because it tries to set OnAwake callback functionality for an object which already needs to exist (meaning it is likely to have already called OnAwake, and the method forces Unity to work around this fact).
So what you can do is check if the sound isPlaying, then if false, call Play()
i.e
void Awake()
{
if (!engineAudio.isPlaying)
engineAudio.Play();
}
Implemented your code Meltown and has solved the problem. Thanks you
Where exactly have you placed these 5 lines?
For each engine AudioSource in the SoundController.js script you need to implement this.
Thank you very much for your quick reply. For newbies like me, I’ve added the complete Awake function.
function Awake()
{
car = transform.GetComponent(Car);
DVolume *= 0.4;
EVolume *= 0.4;
FVolume *= 0.4;
KVolume *= 0.7;
LVolume *= 0.4;
windVolume *= 0.4;
DAudio = gameObject.AddComponent(AudioSource);
DAudio.loop = true;
DAudio.playOnAwake = true;
DAudio.clip = D;
DAudio.volume = DVolume;
if (!DAudio.isPlaying) DAudio.Play(); // <- Bugfix for Unity 3.5
EAudio = gameObject.AddComponent(AudioSource);
EAudio.loop = true;
EAudio.playOnAwake = true;
EAudio.clip = E;
EAudio.volume = EVolume;
if (!EAudio.isPlaying) EAudio.Play();
FAudio = gameObject.AddComponent(AudioSource);
FAudio.loop = true;
FAudio.playOnAwake = true;
FAudio.clip = F;
FAudio.volume = FVolume;
if (!FAudio.isPlaying) FAudio.Play();
KAudio = gameObject.AddComponent(AudioSource);
KAudio.loop = true;
KAudio.playOnAwake = true;
KAudio.clip = K;
KAudio.volume = KVolume;
if (!KAudio.isPlaying) KAudio.Play();
LAudio = gameObject.AddComponent(AudioSource);
LAudio.loop = true;
LAudio.playOnAwake = true;
LAudio.clip = L;
LAudio.volume = LVolume;
if (!LAudio.isPlaying) LAudio.Play();
windAudio = gameObject.AddComponent(AudioSource);
windAudio.loop = true;
windAudio.playOnAwake = true;
windAudio.clip = wind;
windAudio.volume = windVolume;
if (!windAudio.isPlaying) windAudio.Play();
tunnelAudio = gameObject.AddComponent(AudioSource);
tunnelAudio.loop = true;
tunnelAudio.playOnAwake = false;
tunnelAudio.clip = tunnelSound;
// tunnelAudio.maxVolume = tunnelVolume;
tunnelAudio.volume = tunnelVolume;
if (!tunnelAudio.isPlaying) tunnelAudio.Play();
skidAudio = gameObject.AddComponent(AudioSource);
skidAudio.loop = true;
skidAudio.playOnAwake = true;
skidAudio.clip = skidSound;
skidAudio.volume = 0.0;
if (!skidAudio.isPlaying) skidAudio.Play();
carAudio = gameObject.AddComponent(AudioSource);
carAudio.loop = false;
carAudio.playOnAwake = false;
carAudio.Stop();
crashTime = Mathf.Max(crashLowSpeedSound.length, crashHighSpeedSound.length);
soundsSet = false;
idleFadeSpeedDiff = idleFadeStopSpeed - idleFadeStartSpeed;
speedFadeSpeedDiff = speedFadeStopSpeed - speedFadeStartSpeed;
backgroundMusic = gameObject.AddComponent(AudioSource);
backgroundMusic.loop = true;
backgroundMusic.playOnAwake = true;
backgroundMusic.clip = BackgroundMusic;
// backgroundMusic.maxVolume = BackgroundMusicVolume;
// backgroundMusic.minVolume = BackgroundMusicVolume;
backgroundMusic.volume = BackgroundMusicVolume;
if (!backgroundMusic.isPlaying) backgroundMusic.Play();
}