EDIT: I’m a moron… I had disabled info notifications in the Console, so I didn’t see the code working. If you’re a moderator, please delete this embarrassment.
Hello!
So since Unity doesn’t support multiple tags on the same GameObject, I wanted to make my own system. It was very simple: have a script with a dictionary on an object, and have a public function to call to check if it has the tag. Here’s the code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MyTagList : MonoBehaviour {
//point of this script is to have multiple tags
//Not ideal, however I'm kinda short on time and lazy so I'll use this for now
public Dictionary<string, string> tags = new Dictionary<string, string>();
public string IsClickable; //must be "true" or "false"
public string Tag1Value;
public string Tag2Value;
//public float OriginalHP;
//public float CurrentHP;
public string SearchResult;
//public ArrayList ListOfTags;
// Use this for initialization
void Start ()
{
tags["IsClickable"] = "testing";
FindTagName("IsClickable");
}
public void FindTagName(string TagToFind)
{
foreach (KeyValuePair<string, string> KVP in tags)
{
Debug.Log("Found key " + KVP.Key + " with value " + KVP.Value);
}
if (tags.ContainsKey(TagToFind))
{
SearchResult = TagToFind;
}
else
{
SearchResult = TagToFind + " was not found in dictionary.";
}
}
}
It used to work in one of my old projects. However, when I run the code, SearchResult is “IsClickable” (as expected", but the foreach function doesn’t show anything in the console at all. My key (IsClickable) has a value of “testing”, so it is a key value pair. I’ve used dictionaries and KeyValuePair before, so I’m very confused as to what isn’t working here.
Any idea why I can use tags.ContainsKey but can’t find KeyValuePairs in this script?
Thanks for any ideas.
EDIT: I’m a moron… I had disabled info notifications in the Console, so I didn’t see the code working. If you’re a moderator, please delete this embarrassment.