For example, in Scene1 the player is located at (1,2,3) then the scene is changed to Scene2 and the player should be located at (1,2,3) in the new scene.
I figure I’ll need to get the player position first, then change scene, and then translate the player to that position, but I don’t know how I would store that position between scenes.
The best solution for this is to use DontDestroyOnLoad. This will keep the gameobject when transitioning to another scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class dontDestroy : MonoBehaviour {
int scene = 1;
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
if (scene == 1) {
SceneManager.LoadScene("Scene1");
DontDestroyOnLoad(transform.gameObject);
scene++;
} else {
SceneManager.LoadScene("Scene");
scene--;
}
}
}
}