- Home /
Audio affected by Slow Motion?
Hi, I was wondering, since there is a slow-motion mode in my game.. is there a way to have all audio playing at any given time to be slowed down while in slow-mo? It seems that everything except the audio is slowed down, which isn't very "realistic" so I'm hoping there is a solution.
Thanks in advance.
Answer by Tomer-Barkan · Dec 07, 2013 at 07:00 AM
You can set the speed the audio is played by modifying the pitch value of the AudioSource. Setting it to anything lower than 1 will be slow, higher than one will be fast.
Read more about AudioSource here:
http://docs.unity3d.com/Documentation/Components/class-AudioSource.html
If you want it to match the game speed, you can attach this speed to the audio sources:
using UnityEngine;
public class AudioSpeedMatcher : MonoBehaviour {
public void Update() {
audio.pitch = Time.timeScale;
}
}
Thank you for the answer, but I'm getting these two errors:
Assets/AudioSpeed$$anonymous$$atcher.cs(3,31): error CS0103: The name Time' does not exist in the current context Assets/AudioSpeed$$anonymous$$atcher.cs(3,17): error CS0103: The name
audio' does not exist in the current context
Not sure what this means, because I'm not very familiar with C#. Do you know how to fix this?
Sorry, class has to be a monobehaviour of course to attach to an object...
If it doesn't recognize Time, however, you might have forgotten to import the unity engine namespace:
using UnityEngine;
Added both to the code in the answer.
Hmm.. I did forget to add that^. As I said I'm not very familiar with C#, lol. Thank you again, I'll accept your answer.
Your answer
Follow this Question
Related Questions
Heres a Script for SloMo hold left shift 3 Answers
Time.timeScale question 1 Answer
Slow motion problem 1 Answer
How to play sound when object stops moving? 1 Answer
how to get smooth slow motion? 4 Answers