Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Swich Scene?

Discussion in 'Scripting' started by zNiklas, Mar 19, 2015.

  1. zNiklas

    zNiklas

    Joined:
    Mar 19, 2015
    Posts:
    2
    Hey,

    some days ago I started teaching me Unity.
    Now on my second Projekt I have 4 scenes.

    Sooo I have my Player object and an Exit object. When the Player hits the Exit objekt, the next scene shout load.
    Both objects have colliders und ist Exit collider is on "is trigger"

    Then I add a C# to the Exit object:
    using UnityEngine;
    using System.Collections;

    public class Exit : MonoBehaviour {

    void OnTriggerEnter ()
    {
    Application.LoadLevel ("Level2");


    }
    }

    So it doesn't work.
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    First of all, please use code tags.

    Secondly, at least one object requires a rigidbody component for collisions, triggers and their respective callbacks to be fired.
     
  3. zNiklas

    zNiklas

    Joined:
    Mar 19, 2015
    Posts:
    2
    The Player has a rigidbody component
     
  4. Mr-Mud

    Mr-Mud

    Joined:
    Mar 8, 2015
    Posts:
    37
    According to the documentation, you first need to add it to the levels specified in the build settings. Is this something you have done? If not, try that first (take note of the level's name).

    Otherwise, post any errors you are getting. This can give us a better insight in what goes wrong, and thus makes it easier for us to help you.
     
  5. nostalgicbear

    nostalgicbear

    Joined:
    Mar 21, 2013
    Posts:
    98
    As Mr.Mud said above, dont forget to add the levels to the build. Then you can do something like I have below.

    Code (CSharp):
    1. void LoadNextLevel()
    2. {
    3. int i = Application.loadedLevel; //stores the index of the currently loaded level
    4.  
    5. Application.LoadLevel(i+1); //load the next level in the build
    6. }