My game will have hundreds of items/monsters and since I do not want to create a derived class for each of these items/monsters I use a single Monster and Item class, with fields for name, strength, damage, etc, that will differ for each type of item/monster. I have a factory class that will create the Monster/Item instance and automatically pass the field values via the constructor. In then end I can create a new item/monster by passing a monster type enum, like so:
Monster goblin = Factory<Monster>.Create(Monster.Goblin);
The problem is when I create a new monster class instance I don’t know how to attach this particular monster instance as a Component to the new GameObject. I really want to do something like this, which obviously does not work:
Monster goblin = Factory<Monster>.Create(Monster.Goblin);
GameObject game_obj = new GameObject(goblin.Name);
game_obj.AddComponent(goblin);
Does anyone know how to add a particular script instance to a GameObject, or perhaps know of another way to do what I am trying to do?