Hello,
We are developing a game where the audio beats need to be synced with some collisions and trying to debug it especially when the speed of game is high is kind of a pain. When I try to step through in pause mode I dont hear any sound each frame I step through. Is there any way to play the audio while stepping through frame by frame?
Thanks
No, instead to achieve the same result, you could create a simple function that does Time.timeScale = 0.001f;
when you press any button, and Time.timeScale = 1f;
when the button is released.
For example:
void Update()
{
if(Input.GetKeyDown(KeyCode.Q))
{
Time.timeScale = 0.001f;
}
if(Input.GetKeyDown(KeyCode.E))
{
Time.timeScale = 1f;
}
audiosrc[].pitch = Time.timeScale;
}
audiosrc would be an array of type AudioSource
, you would at the Start function use FindObjectsOfType (AudioSource);
and assign that to audiosrc
.
So every time you press Q, all AudioSources ingame will play really slow according to the .timeScale
. And vice versa when pressing E.
0.001f may be too low to actually hear any sound, but you get the idea.
Start with 0.1f and see if that is slow enough for debugging.
You could additionally set the .timeScale
to 0.5f in the Start() function to make it easier to “stop” the frame on time.
PS: If you don’t want to slow ALL audiosources, simply tag those you want with “Slowable”, or similar and use a for loop inside the KeyDown function to only affect the pitch of those with that tag.
Hope this helps!