Skip to content

Instantly share code, notes, and snippets.

@TocaLucas
Last active December 22, 2015 17:29
Show Gist options
  • Save TocaLucas/6506212 to your computer and use it in GitHub Desktop.
Save TocaLucas/6506212 to your computer and use it in GitHub Desktop.
MultiBehaviour
using UnityEngine;
using System.Collections.Generic;
public class MultiBehaviour<T> : MonoBehaviour where T : MonoBehaviour {
private static List<T> _instances;
public static List<T> Instances {
get {
if(_instances == null)
_instances = new List<T>();
return _instances;
}
}
protected void OnEnable() {
if(_instances == null)
_instances = new List<T>();
_instances.Add(this as T);
}
protected void OnDisable() {
_instances.Remove(this as T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment