- Home /
Calling sound once in update
I have a sound for a car and I am using this script
public AudioSource carsound;
public float pitch;
Private bool play;
void Update ()
{
pitch = speed/currentspeed;
carsound.pitch = pitch;
If(play)
{
carsound.Play();
play = false;
}
}
` It plays my sound once my car start but after few seconds my sound stops playing Can anyone solve this ? ;_;
Are you sure the audioSource is looping? (`Loop` checkbox on the AudioSource component)
No it's not looping and I don't even want it to loop I only want to play it once and then change its pitch with respect to my speed
Are you sure nothing destroys the object and that your audioListener is close enough to the audioAource ?
I'd echo what Hellium said here. You need to set your audio to loop. Also, you need to check that the pitch is valid. I could foresee some circumstances where you'd send it an invalid pitch. So, start by setting to loop, and take out the pitch code temporarily, Then, if it works, add back in the pitch code and troubleshoot from there.
Answer by RadonRaph · Jan 29, 2019 at 09:03 AM
Hello, You have the function PlayOneShot() and the properties isPlaying. Learn more here: https://docs.unity3d.com/ScriptReference/AudioSource.html Raph
Tried that too but it misbehaves. The distortion in sound created cause of this ;_;
Your answer
Follow this Question
Related Questions
How to start a sound not from it's start ? 2 Answers
fmod 3d listener only updates once at start of script 0 Answers
Help with sound clips [C#] 0 Answers
How to get decibel's value of game's sound? 0 Answers
Problem with audio 1 Answer