Unity Singleton Pattern
using System;
using UnityEngine;
public class MyScript : MonoBehaviour
{
public static MyScript Instance { get; private set; }
private void Awake()
{
if (Instance != null)
{
Destroy(this);
}
else
{
Instance = this;
}
DontDestroyOnLoad(Instance);
}
}