- Home /
TimeScale with AudioSource
So i searched around and didnt find a solution for my problem. I want that my SoundFile in this script pitches itself with the given TimeScale. "0.2f" is just for testing purposes cause i didnt get it to work and even with this given number the audio doesnt change. The Audiofiles getting decompressed at start and i tryed to use the Doppler Factor, changing this doesnt affect the audio. So iam stucked :D.
public AudioSource SoundSource;
public AudioClip Fire;
SoundSource = GetComponent<AudioSource>();
SoundSource.pitch = 0.2f;
AudioSource.PlayClipAtPoint(Fire, new Vector3(5, 1, 2));
Answer by Souliest · Mar 23, 2018 at 06:21 PM
You are not using the AudioSource to play the clip. As it is, you are setting the pitch on SoundSource, and then using the static function PlayClipAtPoint to play the clip, which does not use SoundSource.
You probably want to do something like this:
public AudioSource SoundSource;
public AudioClip Fire;
SoundSource = GetComponent<AudioSource>();
SoundSource.clip = Fire;
SoundSource.pitch = 0.2f;
// SoundSource.pitch = Time.timeScale;
SoundSource.transform.position = new Vector3(5, 1, 2);
SoundSource.Play();
This way, you set the clip and the pitch (whether you use 0.2f or Time.timeScale) to your audio source, and then use it to play the clip. In the code, I set the transform of the object at the same place you set your PlayClipAtPoint.
Your answer
Follow this Question
Related Questions
Audio Scripting 1 Answer
Audio playing when not colliding issue c# 0 Answers
Is OnAudioFilterRead Still the Preferred Method for Procedural Audio? 0 Answers
Sounds gets distorted when played 0 Answers
fmod 3d listener only updates once at start of script 0 Answers