- Home /
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!
Answer by Alexander-Perrin · Apr 28, 2013 at 05:19 AM
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;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Really want to get into Unity but dont understand coding 1 Answer
Getting keyboard Input 3 Answers
Blender Animations not working properly. 1 Answer
I do a game for the school 1 Answer