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

public class UniqueMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour {

    static T _instance;
    public static T Get {
        get {
            if(_instance == null) _instance = FindObjectOfType(typeof(T)) as T;
            return _instance;
        }
    }

	void Awake () {
        if(transform.parent==null) DontDestroyOnLoad(this);
        T[] obj = FindObjectsOfType<T>();
        for(int i = 0; i < obj.Length; i++) {
            if(obj[i] != null && obj[i] != Get) {
                Destroy(obj[i].gameObject);
            }
        }
	}
}
