Search Unity

How to call a new scene in unity

Discussion in 'iOS and tvOS' started by jpsubbarayalu, Sep 1, 2010.

  1. jpsubbarayalu

    jpsubbarayalu

    Joined:
    Jul 13, 2010
    Posts:
    65
    Hi All,

    Currently i am doing one game application.Here i need to show the level with some fixed time.
    After starting the application i need to show my first seen with Start button.After click Start button it will play my game up to 1 min.Then again it should show the scene Level1 and continue my game.
    1)Here already i done my first scene with start button.After click Start button its playing my game.

    2)Here after one minute i want to call my second scene with Level1 Button.

    Here i don't know how to call my second scene with time.If anybody know about this,Please share your knowledge.


    Thanks in Advance,
     
  2. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    Attach a script to your camera or another game object in the scene.

    Code (csharp):
    1. private var myTimeout:float;
    2. function Start()
    3. {
    4. myTimeout = Time.time+60; // 60 second delay
    5. }
    6.  
    7. function Update()
    8. {
    9. if( Time.time > myTimeout )
    10. {
    11. Application.LoadLevel("TheSceneToLoad");
    12. }
    13. }
     
  3. jpsubbarayalu

    jpsubbarayalu

    Joined:
    Jul 13, 2010
    Posts:
    65
    Thanks for your quick reply.

    My requirement is i want to show the levels while running the application with fixed time.
    After starting my application i need to show my first seen with Start button.After click Start button it will play my game up to 1 min.After that it should show my second scene with Level1 button.If i click Level1 button it again play my game up to 2 min.Then again it should show the scene with Level2 button.If i click Level2 button it will continue to play my game.
    1)Here already i done my first scene with start button.After click Start button its playing my game.

    Below i am using the following code to call my scenes with timing.But its not working.

    var icon : Texture2D;
    var customSkin : GUISkin;
    function OnGUI () {

    //print("GUI----->");
    GUI.skin = customSkin;

    if (GUI.Button (Rect (250,150, 70,50), "Start"))
    {
    //GameController.levelselected=0;
    print("Level0");
    Application.LoadLevel("Second1");
    Invoke("Level1",60);

    }
    GUI.skin = null;
    }

    function level1()
    {
    print("level1 ----------------------------------->");
    if (GUI.Button (Rect (250,230, 70,50), "Level1"))
    {
    //GameController.levelselected=1;
    print("Level11");
    Invoke("Level2",120);
    Application.LoadLevel("Second1");

    }

    }

    function Level2()
    {
    print("Level2");
    if (GUI.Button (Rect (250,310, 70,50), "Level2"))
    {
    //GameController.levelselected=2;
    print("Level22");
    Application.LoadLevel("Second1");
    }
    }
    May i know what is the problem for above code.
    Here my problem is even it was not calling my second function[Level1].I don't know what is the problem.Please help me to sort out this problem.
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Firstly, you are calling Invoke after Application.LoadLevel (this function immediately loads the new level and throws out the current one, so Invoke will not be called). Secondly, assuming this is all one script, it will be unloaded when the new level starts. You need to call the code to load the new level and then in that level, have a script that goes back to the menu after the time is up.
     
  5. jpsubbarayalu

    jpsubbarayalu

    Joined:
    Jul 13, 2010
    Posts:
    65
    Hi,

    Thank you so much your reply.Now its working great.What you mentioning that exactly corrects.



    Thanks,