๐Ÿ“šSingleton

Singleton on Unity

//

์ž‘์—…ํ•˜๋‹ค ์˜ค๋ธŒ์ ํŠธ ์ค‘๋ณต๋ ๋•Œ

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

public class GameManager : MonoBehaviour
{
    public static GameManager instance;

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Debug.Log("Instance already exists, destroying object!");
            Destroy(this);
        }
    }
}

Last updated