ソースコード
using UnityEngine; public static class GameObjectExtensions { /// <summary> /// 新しいシーンを読み込む時に自動で破棄されないようにします /// </summary> public static void DontDestroyOnLoad( this GameObject self ) { GameObject.DontDestroyOnLoad( self ); } }
使い方
// GameObject 型の static 関数で呼び出し GameObject.DontDestroyOnLoad( go ); // 拡張メソッドで呼び出し go.DontDestroyOnLoad();