using UnityEngine;
using System.Collections;

public class PersistantSingleton<Instance> : MonoBehaviour where Instance : PersistantSingleton<Instance> {
	public static Instance instance;
	public bool isPersistant;

	public virtual void Awake() {
		if(isPersistant) {
			transform.parent = null;
			if(!instance) {
				instance = this as Instance;
			}
			else {
				DestroyObject(gameObject);
			}
			DontDestroyOnLoad(gameObject);
		}
		else {
			instance = this as Instance;
		}
	}
}