Hello,
Noob here. I want to smoothly pause the game after pressing Esc. I tried Mathf.Lerp with no success. I assume it’s tied to the fact that the timeScale updates only for a frame on pressing Esc.
So, i want the timeScale to go from 1.0f after pressing Esc and decrease smoothly over a second to 0.0f during which i also move the camera a bit.
This is what i have attached to the Camera:
bool CanPause;
float smooth = 1;
void Start()
{
Time.timeScale = 1;
}
void Update()
{
if (Input.GetButtonDown("Cancel"))
{
if (CanPause)
{
smooth -= smooth * Time.deltaTime;
Time.timeScale = smooth;
CanPause = false;
}
else
{
Time.timeScale = 1;
CanPause = true;
}
}
Also I was getting some out of range values when experimenting with MathfLerp and tried the Mathf.Clamp to keep them between 1.0 and 0.0 to no avail. Please help!