2

I'am trying to made the scene is change after 2 second. Here's my code:

float Czas = Time.time;
if (Czas == 2) {
  Application.LoadLevel("Game");  <-- This is correctly name of the scene
  Debug.Log("Works");
}
Nefrol
  • 23
  • 3

2 Answers2

1

Try with coroutines for "waiting X" with something like this:

void Start()
{
    //Start the coroutine we define below named ChangeAfter2SecondsCoroutine().
    StartCoroutine(ChangeAfter2SecondsCoroutine());
}

IEnumerator ChangeAfter2SecondsCoroutine()
{
    //Print the time of when the function is first called.
    Debug.Log("Started Coroutine at timestamp : " + Time.time);

    //yield on a new YieldInstruction that waits for 5 seconds.
    yield return new WaitForSeconds(2);

    //After we have waited 2 seconds print the time again.
    Debug.Log("Finished Coroutine at timestamp : " + Time.time);
    //And load the scene
    Application.LoadLevel("Game");  <-- This is correctly name of the scene
}
Lotan
  • 4,078
  • 1
  • 12
  • 30
0

There are 2 easy approaches you could take.

1.- As explained in the other answer, use an IEnumerator

ex:

...
StartCoroutine(ChangeAfter2SecondsCoroutine());
...
IEnumerator ChangeAfter2SecondsCoroutine()
{ 
    yield return new WaitForSeconds(2f);
    Application.LoadLevel("Game");  
}

Documentation:StartCoroutine

2.- use Invoke

ex:

...     
Invoke("LoadLevelGame", 2.0f);
...


void LoadLevelGame()
{
     Application.LoadLevel("Game");
}

Documentation: Invoke

IkerG
  • 51
  • 6