Here are shortened versions of your code. If you want time to slow only while you are pressing control, use Input.GetKey() this:
void Update() {
// Slow time while control is pressed.
if (Input.GetKey(KeyCode.LeftControl))
Time.timeScale = 0.1f;
else
Time.timeScale = 1f;
}
If you wanted to toggle the slow motion with control, then use Input.GetKeyDown() like this:
bool slowTime = false;
void Update() {
// When CTRL is pressed, set "slowTime" to the opposite of it's current value.
if (Input.GetKeyDown(KeyCode.LeftControl))
slowTime = !slowTime;
if (slowTime)
Time.timeScale = 0.1f;
else
Time.timeScale = 1;
}
The reason why your code wasn’t working before was because you were using Input.GetKeyDown(), which will only detect the key press for the frame that the key was pushed down.
Input.GetKey() detects continuously so time will slow while CTRL is pressed.
I hope I helped you understand what went wrong and how I fixed it!