How to pause and unpause my game - Input.GetAxis doesn't work when Time.timeScale is 0

I don't seem to be getting any keypress responses to Input.GetAxis() while the Time.timescale is set to zero.

When I set the timeScale to 0.2 (for example) instead of 0, it works fine - so the zero timeScale is definitely the issue.

For example, I have set up a Pause key input - if I press it the game pauses (timeScale = 0) but when I press it again nothing happens (the keypress is not detected).

I have tried setting timeScale to 1 before the GetAxis call and 0 again after but it still doesn't work.

Using Input.GetKeyDown is not an acceptable workaround because there are other keys I want to be able to press while the game is paused, keys that must be definable in the settings.

My actual workaround is this one. When “manager” is in pause, Time.scale is 0.0f

if (manager.pause) {
key_x = Input.GetAxisRaw("Horizontal") / keyMoveSpeed;
key_y = Input.GetAxisRaw("Vertical") / keyMoveSpeed;
} else {
key_x = Input.GetAxis("Horizontal") * Time.deltaTime * keyMoveSpeed;
key_y = Input.GetAxis("Vertical") * Time.deltaTime * keyMoveSpeed;

}

Seems that AxisRaw is collected also when Time.scale = 0, notice that it returns 1, -1 or 0 only from keys. That (for testing) I just divide for the keyMoveSpeed constant (is ugly I know)

When Time.timeScale is set to zero, none of the normal "Update", "FixedUpdate" and similar functions are called, so this is probably the source of your problem - your entire Update function is just not being executed so any code inside will appear to not work.

You can get around this problem by implementing your Pause code in a coroutine, which does not use a Time-based function for the return delay, like this (a c# example) :

public class PauseControl : MonoBehaviour {

    void Start()
    {
        StartCoroutine(PauseCoroutine());    
    }

    IEnumerator PauseCoroutine() {

        while (true)
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                if (Time.timeScale == 0)
                {
                    Time.timeScale = 1;
                } else {
                    Time.timeScale = 0;
                }

            }    
            yield return null;    
        }
    }
}

My actual workaround is this one. When “manager” is in pause, Time.scale is 0.0f

if (manager.pause) {
key_x = Input.GetAxisRaw("Horizontal") / keyMoveSpeed;
key_y = Input.GetAxisRaw("Vertical") / keyMoveSpeed;
} else {
key_x = Input.GetAxis("Horizontal") * Time.deltaTime * keyMoveSpeed;
key_y = Input.GetAxis("Vertical") * Time.deltaTime * keyMoveSpeed;

}

Seems that AxisRaw is collected also when Time.scale = 0, notice that it returns 1, -1 or 0 only from keys. That (for testing) I just divide for the keyMoveSpeed constant (is ugly I know)