user27485
0
Q:

singelton code


using UnityEngine;

public class SingeltonObject : MonoBehaviour
{

    void Awake()
    {
        SetUpSingelton();   
    }

    private void SetUpSingelton()
    {
        if (FindObjectsOfType(GetType()).Length > 1)
        {
            Destroy(gameObject);
        }
        else
        {
            DontDestroyOnLoad(gameObject);
        }
    }
}
1

Tags

New to Communities?

Join the community