Change Scene/Level on Trigger

first a few checks,
make sure you have your player tagged as “Player”
make sure you have all scenes in build settings, add all scenes
save your entire project

The Trigger to Change Scene
create a plane/sphere/cube something to act as the trigger and select is trigger

  • create a C# script called something like LevelManager or SceneManager, attach it to your trigger object and open in MonoDevelop or VS
  • clear “void Start()” and “void Update” as they are not needed and create “void OnTriggerEnter(Collider ChangeScene)” and the { }
  • in this function we type if( ChangeScene.gameObject.CompareTag(“Player”)) and open { } ← them

you don’t have to put Collider ChangeScene you can use whatever is easiest for you, it doesn’t matter as long as you have your Collider or Collider2D the ChangeScene is the name you choose it to be called

The if statement tells your trigger object, if the player hits you change the scene, ight trigger? and trigger says ight man no problem I got your back. They cool with eachother like that.

and CompareTag(“Player”) is your player that should already be tagged as player. if its not youll get an error.

  • in the if statement we type “Application.LoadLevelAdditive(1);

Application is your application… obviously right…? and the int or the number in the brackets is the scene number in your build settings. remember I said a few checks? that’s why or else the level wont load. the on can be replaced with 2, 3, 4, 5 etc… its the scene you want loaded.

Here is a code sample to see for yourself ight,

void OnTriggerEnter(Collider ChangeScene) // can be Collider HardDick if you want.. I'm not judging you
{
    if(ChangeScene.gameObject.CompareTag("Player"))
    {
        Application.LoadLevelAdditive(1); //1 is the build order it could be 1065 for you if you have that many scenes
    }
}

//Traxxy Out
3 Likes

[QUOTE=

  • Application.LoadLevelAdditive(1);

[/QUOTE]

How do we avoid multiple loads of the additive scene if the player walks back through the trigger?

Add a destroy game object

:)thank you

i m french and your script does not work can you help me please

1 Like

its really old they don’t use the same directories any more

kjhgfdddddss

doesn’t work for me. i have tried so many videos and tutorials to get it working but it doesn’t want to

Hey bro I was wondering how do I make it so same script different triggers go to diff scenes do I duplicate the scripts and change the number

using UnityEngine.SceneManagement;

public class ChangeScene : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
SceneManager.LoadScene(“SceneName”);
}
}

//The collider must click IsTrigger, so that when Player pass there can trigger and change scene
//Is it work for u guys?

Here is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class gotonextstahe : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        SceneManager.LoadScene("Stage02");
    }
}

And it works with me just find.
Don’t forget to add collider and check isTrigger, when the player collide the object, he will jump to the mentioned scene.

2 Likes

Do I put this on the object in question or the Player, @iSoloXIV ?