Skip to content

Instantly share code, notes, and snippets.

@farukcan
Created January 14, 2022 20:05
Show Gist options
  • Save farukcan/21c516e1c947c52f42155b2ecb048ced to your computer and use it in GitHub Desktop.
Save farukcan/21c516e1c947c52f42155b2ecb048ced to your computer and use it in GitHub Desktop.
Advanced Multiple Tagging instead of Unity's
// Author : github.com/farukcan
// Usage : AdvancedTag.GetTagList("Player")
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AdvancedTag : MonoBehaviour
{
private static Dictionary<string, List<GameObject>> dictionary = new Dictionary<string, List<GameObject>>();
public string[] tags;
public static List<GameObject> GetTagList(string tag)
{
if (dictionary.ContainsKey(tag))
{
return dictionary[tag];
}
else
{
return dictionary[tag] = new List<GameObject>();
}
}
private void OnEnable()
{
foreach(var tag in tags)
{
var list = GetTagList(tag);
list.Add(gameObject);
}
}
private void OnDisable()
{
foreach (var tag in tags)
{
var list = GetTagList(tag);
list.Remove(gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment