Assigning a GameObject to a class

Going to go ahead and re-ask this question, because on my old thread everyone kept commenting on the first answer which was irrelevant to the quesiton… Anyway, my goal is to create a NPC System without using MonoBehaviour, so I will be creating NPCs via script, and using Instancing to get all of their stats… Here is a basic script for getting the stats for the NPC.

public class NPCs
{
    public NPC[] npcList;
    public int npcId;

    void createNPC()
    {
       npcId = npcId + 1;
       npcList[npcId].maxHealth = 100;
        npcList[npcId].CurrentHealth = npcList[npcId].maxHealth;
       npcList[npcId].expReward = 50;
    }

    public class NPC
    {
       public int currentHealth {get; set;}
       public int maxHealth {get; set;}
       public int expReward {get; set;}
    }
}

What I’m trying to figure out how to do is bind the NPC class to the created GameObject, because With this current script I can “Create” a NPC and Modify it’s values, although there is no visual game object. For this I need to create it. The reason this is so important is I am going to combine it with my targetting system and use it to grab these values. I’m thinking about putting a GameObject in the npc class, and defining it in the createNPC constructor… but I’m not sure yet.

Note: using MonoBehaviour would be best solution here, it doesn’t cost u anything and provide much simplification for your code. But assuming there is really important reason why you cannot use that (i cannot imagine such, but well … its up to you):

Best would be to create static Dictionary, that will map game objects to NPC class instances, like that:

public class NPCs {
    public Dictionary<GameObject, NPC> npcList = new Dictionary<GameObject, NPC>();

    void createNPC() {
       // Instantiate game object here
        GameObject npcGameObject = InstantiateFunction(); // This function must create GameObject, for example instantiate prefab, and return it
        NPC npc = new NPC();
        npcList.Add(npcGameObject, npc);
        npcList[npcGameObject].maxHealth = 100;
        npcList[npcGameObject].CurrentHealth = npcList[npcId].maxHealth;
        npcList[npcGameObject].expReward = 50;
    }

    public class NPC {
       public int currentHealth {get; set;}
       public int maxHealth {get; set;}
       public int expReward {get; set;}
    }
}

Such solution provides you both game object and npc object in one single place, you can access npc object easly by giving gameObject instance.