Skip to content

Instantly share code, notes, and snippets.

@mandarinx
Created June 6, 2013 14:34
Show Gist options
  • Save mandarinx/5721966 to your computer and use it in GitHub Desktop.
Save mandarinx/5721966 to your computer and use it in GitHub Desktop.
#if UNITY_EDITOR
void SingleComponentCheck() {
var components = gameObject.GetComponents(this.GetType());
foreach (var component in components) {
if (component == this) continue;
UnityEditor.EditorUtility.DisplayDialog("Can't add the same component multiple times!",
string.Format("The component {0} can't be added because {1} already contains the same component.", this.GetType(), gameObject.name),
"Cancel");
DestroyImmediate(this);
}
}
protected virtual void Reset() {
Invoke("SingleComponentCheck",0);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment