Dssdiego
4/22/2020 - 4:33 PM

Singleton Pattern

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