AudioSources don't play when setting Time.timescale = 0

I’m using the standard trick of setting Time.timescale = 0 to pause my game. Then I present buttons when paused to restart the level, go to the main menu, mute, shop, etc. I want to play a consistent button sound across all UI buttons when clicked, but when in game pause, my button clip doesn’t play immediately. I assume that Time.timescale=0 tells Unity to also pause new audiosources. Is there any way around this and to make them play immediately? I can’t find anything on the forum or in documentation. Thanks.

2 Answers

2

What method are you using to play the sounds? Are you sure it’s being called?

This bit of JavaScript seems to work fine:

@script RequireComponent(AudioSource)

function Start()
{
	Time.timeScale = 0f;
	audio.Play();
}

void Start() { Time.timeScale = 0f; this.audioDevice.Play(); } in C#

void Start()
{
Time.timeScale = 0f;
this.audioDevice.Play();
}

in C#