Search Unity

Unusual problem when loading a scene

Discussion in 'Editor & General Support' started by Rob64, Jun 10, 2012.

  1. Rob64

    Rob64

    Joined:
    Aug 15, 2010
    Posts:
    18
    I've put this here because I'm not sure if it's a scripting problem or not.


    I have a simple test project with two scenes, a title scene and a

    game scene. The script shown works perfectly when used with the title

    scene and it loads the game scene with the 3 second delay.

    If I use this same script in my other main project in the same way

    it will not work WITH THE INVOKE FUNCTION. I have a few scenes in that

    project and it will not load any, but If I COMMENT OUT THE INVOKE

    FUNCTION it will load any scene.

    I have also tried the yield WaitForSeconds function too, this does

    the same thing, working in one project but not the other.

    There are no errors showing in the console. When the button is

    pressed in the menu scene it just stays at the menu scene. The scenes

    have been added to the build settings box. I've also tried making

    another simple menu and game scene in the main project and even these

    don't work with the delay functions.

    Why should the same script with an invoke function work in one

    project but not another.

    I've loaded the latest Unity update but it didn't make any

    difference.


    var customSkin:GUISkin;

    function OnGUI () {

    if(GUI.Button(Rect(0,0,100,35),"Play Game")){
    Invoke( "WaitAndLoad", 3.0 );
    }
    }

    function WaitAndLoad(){
    Application.LoadLevel ("Test Game") ;

    }
     
  2. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    Do you change the name level of this "Application.LoadLevel ("Test Game") ;" to its correct name? And don't forget to make sure that the "scene in build" (File -> Build Settings) has the scene that you want to load.
     
  3. Rob64

    Rob64

    Joined:
    Aug 15, 2010
    Posts:
    18
    As I mentioned, all the scenes are in the Build settings box, and the names of the scenes are changed in the script before I try to load different scenes. I'm thinking it may be something in this particular project that is not allowing a delay before a scene is loaded, anyone got any ideas.
     
  4. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    Does it load the levels when you load it normally without delay?

    I know you have try WaitForSecond but have you tried this way:
    Code (csharp):
    1.  
    2. function OnGUI () {
    3.  
    4. if(GUI.Button(Rect(0,0,100,35),"Play Game")){
    5.      WaitAndLoad ();
    6. }
    7. }
    8.  
    9. function WaitAndLoad(){
    10.  
    11. yield WaitForSeconds (3);
    12. Application.LoadLevel ("Test Game") ;
    13.  
    14. }
     
  5. Rob64

    Rob64

    Joined:
    Aug 15, 2010
    Posts:
    18
    Thanks henry64, yes as I mentioned it will load the levels without using the delay.
    I tried the script you suggested and it behaves like all the rest of the scripts I've tried, in the test project it works but in my main project it doesn't, the menu scene just hangs there and any other scene will not load. It seems to me that it's not so much a script problem but something in my main project maybe but I don't want to start all over again making a new terrain etc.