How do I change scene by walking through a door?

I am trying to change scene (like walking through the door in the game PT silent hills). However I don’t know how to script that into my scene. I don’t necessarily know the technical term for what I am trying to accomplish so I haven’t been able to find any video walkthroughs. My map is one corridor that I want to lead to an exact replica of the previous corridor (again kind of like PT).

If your going to switch scenes then you need to access the SceneManager on top of your script.
What I recommend doing if your going to do this a lot in your game is to create a string for the scene name, its what I always use as it allows more control . Code looks like this.

up top by all the using statements.
using.Unity.Engine.SceneManagement;

public string sceneToSwitchTo;

void SwitchScene()
{
SceneManager.LoadScene(sceneToSwitchTo);
}

another way to do this is to either type in SceneManager.LoadScene(“NAMEOFSCENE”);

The issue with this is your stuck then with that scene, using my first method you go into the inspector and you type in the name of your scene next to where it says “sceneToChangeTo”. Its handy because you can pop it anywhere and switch to any scenes you want to.

On terms of how to apply this with your walking through a door idea, put a collider onto your door and set it to a trigger. Give your player a tag i.e “Player”.
Now on door with the collider add the script i’ve put above, but dont do it inside the void. Instead do this…

private void OnTriggerEnter(Collider other)
{
If(other.CompareTag(“Player”)
{
SceneManager.LoadScene(sceneToSwitchTo);
}

As long as your player gameobject is tagged with “Player” or whatever Tag you wish to use that matches with the “other.CompareTag” then you will switch Scenes upon touching it.

Side note, its a common noob error i always make, make sure whatever scene your going to switch to is in your build settings otherwise nothing will happen lol. Ive done it plenty of times. If your not sure how to do it, simply open that scene then click build settings and then click on add open scenes. :slight_smile: