Access tag from list

Hi, I have some problems with a script I’m working on and would love some help.

Functionality

When you look at an object a text appears on the screen. Most of it works but right now I’m trying to figure out a way to have a different text depending on what the tag of the objects are. Obviously I can write multiple lines of code for it but I’m trying to work with lists so I have the option to choose the name of the tag and text for the popup.

The problem

I’m trying to access the tag (hitTag) which is written in the inspector but I only get the error "The name ““hitTag” does not exist in the current context” (same with hitText).

I’m pretty new when it comes to lists so if you guys have a better idea how to fix this I’m all ears! Thanks in advance!

Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class ManagerUI : MonoBehaviour
{
    [Header("Hit Text")]
    public TMP_Text textObject;
    public float hitDistance = 2.0f;

    public List<textGroup> textElements = new List<textGroup>();
    [System.Serializable] public class textGroup
    {
        public string hitText;
        public string hitTag;
    }

    void Update()
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

            if (Physics.Raycast(ray, out hit, hitDistance) && hit.collider.tag == hitTag)
            {
                textObject.text = hitText;
                textObject.enabled = true;
            }
            else
            {
                textObject.enabled = false;
            }

            if (hitDistance < 2.0f)
            {
                textObject.enabled = false;
            }
    }
}

Code NOT TESTED

public class ManagerUI : MonoBehaviour
{
    [Header("Hit Text")]
    public TMP_Text textObject;
    public float hitDistance = 2.0f;
    private Camera mainCamera;

    public List<TextGroup> textGroups = new List<TextGroup>();
    [System.Serializable] public class TextGroup
    {
        public string hitText;
        public string hitTag;
    }

    void Start()
    {
        mainCamera = camera.main;
    }

    void Update()
    {
        Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, hitDistance))
        {
            TextGroup hitTextGroup = GetHitTextGroup(hit.collider.gameObject);
            if(hitTextGroup != null)
            {
                textObject.text = hitTextGroup.hitText;
                textObject.enabled = true;
            }
            else
            {
                textObject.enabled = false;
            }
        }
        else
        {
            textObject.enabled = false;
        }

        if (hitDistance < 2.0f)
        {
            textObject.enabled = false;
        }
    }

    TextGroup GetHitTextGroup(GameObject gameObject)
    {
        foreach(TextGroup group in textGroups)
        {
            if(gameObject.CompareTag(group.hitTag))
                return group;
        }

        return null;
    }
}