How would I get data out of a list of lists? (Made from a "List Wrapper")

Currently I am trying to basically create a “tag system” in which one object could take two objects which both have the script “Object Tag” and send their names to a script that would decide whether the first object could be built on top of the second object. (Think like “Indoors vs Outdoors” from Prison Architect for example)

Here’s the code for a “String List Wrapper”:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class StringListWrapper
{
    public string tagName;
    public List<string> tagList;
}

The “tagName” refers to the tag of the structure the player is trying to build, wheras the “tagList” refers to the list of other objects that the player is allowed to build that structure on top of.

Here’s the code for the “Tag Checker”:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tags : MonoBehaviour {

    public GameObject object1;
    public GameObject object2;

    public List<StringListWrapper> tags = new List<StringListWrapper>();

    private void Start()
    {
        TagCheck(object1, object2);
    }

    public void TagCheck(GameObject gO1, GameObject gO2)
    {
        List<string> TagSet1 = gO1.GetComponent<ObjectTag>().tags;
        List<string> TagSet2 = gO2.GetComponent<ObjectTag>().tags;

        bool check = false;

        for (int i = 0; i < TagSet1.Count; i++)
        {
            Debug.Log(tags*);*

}

}
}
What I am hoping to do is find an item in the “tags” list from the “Tags” script using a string name. But what I have found is that each item in the “tags” list is simply a “StringListWrapper”. (As you can see I did a debug of the “tags” index.
If you need anymore clarification just ask! Also, if you have a suggestion for a better way of reaching my eventual goal please, tell me.
Thank you,
— expat1999

If I understood right, you want this:

  • Every structure describes itself with
    a “tag”.
  • Every structure describes on
    top of which other structures it can
    be built with a collection of tags.

If you want this functionality in a Tags script, you could make it like this:

using System.Collections.Generic;

public class Tags: MonoBehaviour
    {
        public string tag;
        public HashSet<string> canBeBuiltOnTopOf = new HashSet<string>();
    
        public static bool CanBeBuiltOnTopOf(GameObject g1, GameObject g2)
        {
            var tags1 = g1.GetComponent<Tags>();
            var tags2 = g2.GetComponent<Tags>();
            if(tags1 == null || tags2 == null)
            {
                return false;
            }
    
            return tags1.canBeBuiltOnTopOf.Contains(tags2.tag);
        }
    }

Then you could use it like this:

bool allowed = Tags.CanBeBuiltOnTopOf(gameobject1, gameobject2);

In your loop you are iterating through your current class member tags List of type StringListWrapper

In your Loop if you change

Debug.Log (tags )
To:
Debug.Log (TagSet1*)*
It should return a string…
If you want to return the String field of your type StringListWrapper foreach item in your tag set
You’ll need to change debug log to:
Debug.Log (tags*.tagName)*