How to maintain player position between scenes?

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--;
            }
        }
    }
}

Hello i will give you an easy solution but i don´t know if it is the best solution.

in the Start method in someone class in the player´s prefab write this lines of code.

void Start()
{
transform.position=new vector3(x,y,z);
}

(x,y,z) are starting point. I don´t know if it is usefull for you. If you need more about it ask and i will help you if is possible.

Cheers