Search Unity

Loading a Level

Discussion in 'Scripting' started by SweetRevenge, Dec 7, 2010.

  1. SweetRevenge

    SweetRevenge

    Joined:
    Aug 28, 2010
    Posts:
    26
    I'm trying to make a 2d platform, and I want to make a Loadlevel script that when the player gets within a certain distance of a teleport platform, it will load the next level. So that being said, I understand it will require a raycast to find the player, and then a Application.LoadLevel("Level2"); can anyone help me out with putting it all together?
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    It shouldn't require a raycast (using a trigger would be a more typical solution).
     
  3. LuckyDog

    LuckyDog

    Joined:
    Nov 24, 2010
    Posts:
    97
    Well you can do what I did, I made a case statment and tagged my level exits something diffrent for each case here is some of the script:

    //Exit level functiion
    function OnControllerColliderHit (hit : ControllerColliderHit)
    {
    switch (hit.gameObject.tag)
    {
    case "LevelExit1":
    Application.LoadLevel(2);
    break;
    }
    }

    After that you would use a new tag such as "LevelExit2" And that case would make it load level 3
     
  4. LuckyDog

    LuckyDog

    Joined:
    Nov 24, 2010
    Posts:
    97