unity保持切换场景对象不变

问题遇到的现象和发生背景

如何在unity当切换到下一个场景后再返回上个场景时,保持上个场景所有对象不变

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

public class gm : MonoBehaviour
{
    public GameObject panel;
    // Start is called before the first frame update
    void Start()
    {
        panel.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
       if (Input.GetKeyDown(KeyCode.Escape))
        {
            Time.timeScale = 0;
            SceneManager.LoadScene(2);
        }
    }

    public void GameOver()
    {
        Time.timeScale = 0;
        panel.SetActive(true);
    }

    public void Restart()
    {
        Time.timeScale = 1;
        SceneManager.LoadScene(1);
    }
    public void Res()
    {
        Time.timeScale = 1;
        SceneManager.LoadScene(0);
    }
    public void Ant()
    {
       
    }
    
}


当你离开一个场景重新进入时你之前在该场景做的操作都会被初始化,除非你在离开旧场景前将所有发生变化的操作进行记录(比如记录下物体最后的位置角度)通过持久化存储或者静态变量等等的方式记录下来,再次进入该场景时进行读取和重新赋值。

试试多场景,和活跃场景呢