Search Unity

SplashScreen handoff via time

Discussion in 'Scripting' started by Cosmas, Apr 1, 2010.

  1. Cosmas

    Cosmas

    Joined:
    Jan 9, 2010
    Posts:
    133
    I'm trying to display 2 splash screens, each one in its own scene.

    Code (csharp):
    1.    
    2. void FixedUpdate()
    3. {
    4.    print(Time.timeSinceLevelLoad);
    5.    if (Time.timeSinceLevelLoad == 3.0 || Input.GetKey("escape") )
    6.  
    7. Application.LoadLevel("NextLevel");
    8. }
    9.  
    10.  
    I know FixedUpdate is generally only for phys data, but I wouldn't think it should affect this. I have this script placed on the camera in both scenes.
    This makes it to the second screen then the clock runs over 3 seconds into oblivion and never loads the third scene.
    What am I doing wrong here?
    Thanks

    *EDIT: Also the "NextLevel" is unique per scene. So Level 1 > Level 2. Level 2 > Level 3.
     
  2. Cosmas

    Cosmas

    Joined:
    Jan 9, 2010
    Posts:
    133
    Ah ok,

    I changed:

    Code (csharp):
    1. Time.timeSinceLevelLoad == 3.0

    to:

    Code (csharp):
    1. Time.timeSinceLevelLoad > 3.0
    But I don't quite understand why that worked. I would think that equality is just as good of a test. Guess I need to bust out my programming 101 book.
     
  3. burnumd

    burnumd

    Joined:
    May 27, 2008
    Posts:
    367
    Yeah, == isn't going to work except in infinitesimally rare circumstances. If FixedUpdate doesn't occur precisely when the time since the level was loaded is 3, you're never going to trigger that condition (typically, it'll be 3.029483... or something). So if you check for whenever the timer is >= 3, you'll hit it as soon as the timer has passed 3.