I want to make a game, where you can enter different buildings.
To teleport into another scene i use a simple script. ( image 1)
But when I change the scene, there is just one spawn location.
For example ( image 2) when I enter the building (from the streets) I want to spawn at the stairs, but when I leave a room, I want to spawn infront of the door.
Can somebody help me, please?
I assume that you have different objects that you use for triggers. If the player enters the trigger, the code in the first image loads the scene. You need a script that manages the actions you want to perform after loading a screen.
using UnityEngine;
using UnityEngine.SceneManagement;
public class ExampleCode : MonoBehaviour
{
int previousScene = 0;
void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
// Check scene.buildIndex and do things according to previousScene
// For example, if scene.buildIndex is 0 and previousScene is 1, you entered the building from the streets, so set the character position to the stairs
// If scene.buildIndex is 0 and previousScene is 2, you left the room, so set the character position to the door
previousScene = scene.buildIndex;
}
}