Skip to content

Commit 93bdbf5

Browse files
committed
fix(game-pause): use Time.timeScale for global pause
1 parent fc8f9f4 commit 93bdbf5

File tree

3 files changed

+4
-32
lines changed

3 files changed

+4
-32
lines changed

‎Assets/Scripts/DayAndNightCycler.cs‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public class DayAndNightCycler : MonoBehaviour
99
private float _rotationAngleStep;
1010
private Vector3 _rotationAxis;
1111

12-
private Coroutine _starsCoroutine = null;
13-
1412
private void Start()
1513
{
1614
// apply initial rotation on stars
@@ -23,35 +21,7 @@ private void Start()
2321
_starsRefreshRate = 0.1f;
2422
_rotationAxis = starsTransform.right;
2523
_rotationAngleStep = 360f * _starsRefreshRate / GameManager.instance.gameGlobalParameters.dayLengthInSeconds;
26-
if (!GameManager.instance.gameIsPaused)
27-
_starsCoroutine = StartCoroutine("_UpdateStars");
28-
}
29-
30-
private void OnEnable()
31-
{
32-
EventManager.AddListener("PausedGame", _OnPausedGame);
33-
EventManager.AddListener("ResumedGame", _OnResumedGame);
34-
}
35-
36-
private void OnDisable()
37-
{
38-
EventManager.RemoveListener("PausedGame", _OnPausedGame);
39-
EventManager.RemoveListener("ResumedGame", _OnResumedGame);
40-
}
41-
42-
private void _OnPausedGame()
43-
{
44-
if (_starsCoroutine != null)
45-
{
46-
StopCoroutine(_starsCoroutine);
47-
_starsCoroutine = null;
48-
}
49-
}
50-
51-
private void _OnResumedGame()
52-
{
53-
if (_starsCoroutine == null)
54-
_starsCoroutine = StartCoroutine("_UpdateStars");
24+
StartCoroutine("_UpdateStars");
5525
}
5626

5727
private IEnumerator _UpdateStars()

‎Assets/Scripts/Managers/GameManager.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ private void OnDisable()
118118
private void _OnPausedGame()
119119
{
120120
gameIsPaused = true;
121+
Time.timeScale = 0;
121122
}
122123

123124
private void _OnResumedGame()
124125
{
125126
gameIsPaused = false;
127+
Time.timeScale = 1;
126128
}
127129

128130
/* game parameters update */

‎Assets/Scripts/Managers/SoundManager.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private IEnumerator _TransitioningVolume(string volumeParameter, float from, flo
5454
while (t < delay)
5555
{
5656
masterMixer.SetFloat(volumeParameter, Mathf.Lerp(from, to, t / delay));
57-
t += Time.deltaTime;
57+
t += Time.unscaledDeltaTime;
5858
yield return null;
5959
}
6060
masterMixer.SetFloat(volumeParameter, to);

0 commit comments

Comments
 (0)