DontDestroyOnLoad.csを作る。
using UnityEngine; public class DontDestroyOnLoad : MonoBehaviour { void Awake() { DontDestroyOnLoad(this.gameObject); } }
上記のような スクリプトを作ります。
補足
シーンを跨いだ時に削除したくないオブジェクトにアタッチします。
今回はキューブAにアタッチします。

再生ボタンを押すとこのような表示になります。

「シーン切り替えボタン」を押してみましょう。

『DontDestroyOnLoad.csのアタッチされたキューブA』は削除されない。
『DontDestroyOnLoad.csのアタッチされていないキューブB』は削除される。