- Home /
Question by
rekt_son_yt · Apr 21, 2019 at 09:14 AM ·
scene-loadingtime.deltatimescene loadtime.timescale
how to reset deltatime back to 1f when scene has reloaded?,
so whenever my character has hit an object, it slows the time by 0.5f, then slowly brings the time back to 1f within the span of 5 seconds, then the scene will reload. The problem is, whenever the scene has been reloaded, the deltatime is still slowed down by 0.5f, and not returning to normal, any solutions?
here is the script on my gameobject responsible for slowing, and fast forwarding the time { public float slowdownFactor = 0.05f; public float slowdownLength = 2f;
void Update()
{
Time.timeScale += (1f / slowdownLength) * Time.unscaledDeltaTime;
Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
}
public void DoSlowmotion ()
{
Time.timeScale = slowdownFactor;
Time.fixedDeltaTime = Time.timeScale * .02f;
}
}
Comment
Answer by wiecek1873 · Aug 03, 2020 at 11:25 AM
@rekt_son_yt Hi man I'm working on exactly same code. Here is solution that work for me.
void Update()
{
Time.timeScale += (1f / slowdownLength) * Time.unscaledDeltaTime;
Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
//Without this line you don't change Time.fixedDeltaTime when going back to "normal"
Time.fixedDeltaTime = Time.timeScale * 0.02f;
}
public void Slowmotion(object sender, EventArgs args)
{
Time.timeScale = slowdownFactor;
Time.fixedDeltaTime = Time.timeScale * 0.02f;
}