- Home /
Get Input while Time.timescale == 0?
Hey,
I want to controle my pausemenu by keyboard input but Time.timescale is set to 0 for pausing the game. Is there another way to perform keyboard input based events than using the updatefunction?
Answer by rutter · May 13, 2013 at 10:19 PM
Active components should still get Update() calls while time is frozen, but bear in mind that Time.deltaTime will always be zero (this can cause funky behavior if you're not expecting it). If it's not being called, your component is probably missing or inactive.
It's simple enough to test if Update() is getting called by putting a simple log statement in there.
Oh, stupid me trying to use "GetAxis" ins$$anonymous$$d of "GetButton".. Forgot that Axis take time until they reach 1/-1.. so while timescale is set to 0 they will stay at 0.. Thanks and Sorry ;)
No problem! That's why we're here. :)
$$anonymous$$y classic mistake is pausing, then wondering why UI animations stop moving.
also as an addition you could do 1/curFrameRate to allow you to still do time based animations without being affected by Time.deltaTime.
If I use EditorApplication.isPaused to pause the editor, how do i unpause it from a script? none of the scripts will get update functions then, right?
Is that why everyone seems to be using Time.timescale = 0 ins$$anonymous$$d?
I kind of want the editor buttons to match the current state properly when i'm debugging.
all i really wanted was to have a different hotkey to pause the editor because the one they chose was a pretty poor choice. Can't use the mouse and pause with just two hands
Answer by Tabemasu Games · Sep 08, 2014 at 04:19 PM
You can also use the Input.GetAxisRaw method, which will work even when timeScale = 0.
Answer by joshluna · May 24, 2020 at 12:13 PM
GetAxis uses Time.deltaTime to smooth the value by Sensitivity/Gravity settings from the Input configuration, therefore it respects Time.timeScale. You can use GetAxisRaw, but that will no longer respect Sensitivity/Gravity. This will apply smoothing using Time.unscaledDeltaTime, but it might produce different results, not sure exactly how GetAxis resolves.
private void GetSmoothRawAxis(string name, ref float axis, float sensitivity, float gravity)
{
var r = Input.GetAxisRaw(name);
var s = sensitivity;
var g = gravity;
var t = Time.unscaledDeltaTime;
if (r != 0)
{
axis = Mathf.Clamp(axis + r * s * t, -1f, 1f);
}
else
{
axis = Mathf.Clamp01(Mathf.Abs(axis) - g * t) * Mathf.Sign(axis);
}
}
Thanks, this solved my issue of not being able to scroll around my map with the game paused. It looks pretty spot on compared to GetAxis!
Your answer
Follow this Question
Related Questions
Controlling pause menu with keyboard in Unity 4.6? 1 Answer
Pause Game Through Button UI Click Instead of Escape Key? 2 Answers
Android keyboard pauses app, and doesn't release it 1 Answer
Script Not workin 1 Answer
Pausing game 1 Answer