I need to create a index of a lot of tags so i can use this to look up these tags very easy.
You may want a hash map like Dictionary in C#. Check it out here:
I assume you want fast lookup from tags to the GameObects with those tags, in which case you probably want something like:
Dictionary<string, List<GameObject>>
Edit: changed GameObject to List
If you want to grab all gameObjects in the scene and add their tags to a List:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FindTags : MonoBehaviour
{
List<string> tags = new List<string>();
void Start()
{
foreach(GameObject go in GameObject.FindObjectsOfType (typeof(GameObject)))
tags.Add (go.tag);
foreach(string tag in tags)
print (tag);
}
}
If you want to name the tags manually:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TagList : MonoBehaviour
{
string[] temp;
List<string> tags = new List<string>();
void Start()
{
temp = new string[]{"Tag1", "Tag2", "Tag3", "Tag4"};
tags.AddRange (temp);
if(tags.Contains(tag))
print ("This gameObject's tag index is: "+tags.IndexOf(this.tag));
else
print ("This gameObject's tag does not exist in your list!");
}
}