Theoretically, setting timesScale to 0 right when you press the New Game button would work (unless you have some kind of crazy cool animation going on), however, if that is not an option, you can try adding this to your C# class:
public void OnLevelWasLoaded(int level)
{
if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
{
Time.timeScale = 0;
}
}
If you need to wait a few seconds after the scene has loaded (to get the ball rolling), then you can do one of the following:
ONE:
public void OnLevelWasLoaded(int level)
{
//Directly call a Coroutine, allowing you to yield for a number of seconds:
//(Coroutines are functions that can are excecuted "simultaneously" to other functions (when they yield, other functions continue excecution)
//This allows you to program in delay, without stopping the rest of your game
if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
{
StartCoroutine(OnLevelWasLoaded_Coroutine(level));
}
}
public IEnumerator OnLevelWasLoaded_Coroutine(int level)
{
yield return new WaitForSeconds(10);
//yield return yields until the following statement (which is in this case new WaitForSeconds()) returns.
//new WaitForSeconds() causes a pause of the given amount of seconds before returning.
}
Or, TWO:
//Unity automatically sees that this is an IENumerator, and starts it as a coroutine without you having to. This is cleaner code, but a bit slower, as we check if this was the correct scene AFTER the coroutine is started, instead of BEFORE.
public IENumerator OnLevelWasLoaded(int level)
{
if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
{
yield return new WaitForSeconds(10);
StartCoroutine(OnLevelWasLoaded_Coroutine(level));
}
}
OnLevelWasLoaded: [http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html][1]
Unity C# Coroutines: [http://www.blog.silentkraken.com/2010/01/23/coroutines-in-unity3d-c-version/][2]
[1]: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html
[2]: http://www.blog.silentkraken.com/2010/01/23/coroutines-in-unity3d-c-version/
↧