Make code execute for a specified time?

Once i click a cube in my game i wish for the timescale to be half, therefore halfing the games time, the problem is how do i do this for say 5 seconds? Is there any way of possibly keeping it in the slowed state for 5 seconds?

Im new to unity so thanks!

1 Answer

1

http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html

Check out coroutines. You can use ‘WaitForSeconds()’ to do this fairly easily.

But be aware that you would have to wait for 2.5 seconds not 5 using WaitForSeconds if you'd halved the timescale.

The following in a coroutine will wait for 5 seconds even if the timeScale is 0 (c#): var t = Time.realtimeSinceStartup; while((Time.realtimeSinceStartip - t) < 5) yield return null;