0
\$\begingroup\$

I have a need to pause my game and the simplest and most clean way that I know of (other than completely designing my own time system) is by using Time.timeScale = 0;

However, this also makes my CameraController script stop working, because it relies on LateUpdate() and FixedUpdate() to update the camera position.

How would I change the timescale for other things that rely on it, but leave the part of it that the CameraController works with intact?

My first thought was adding a variable int isPaused; to parts of code that need to be stopped, and then instead of actually setting the timeScale to 0, I'd just change that isPaused variable to zero, and then multiply it with Time.deltaTime as usual, which would result in that object not moving, while still keeping my CameraController working. However, I'm not sure if this is the cleanest and simplest way to achieve something like this. Perhaps designing my own time system would be more beneficial in the long run?

Here's the CameraController code incase it is needed: https://hatebin.com/fqtybcuwht

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Nothing wrong with what you've suggested. I would use another float value - just like Time.timeScale itself - which is set to either 0.0f or 1.0f, to multiply by in all scripts except your CameraController. It becomes 0.0f when you pause, 1.0f otherwise.

This way, you also avoid conditionals - multiplication is cheaper than checking if (someFlag) ...

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .