Okay, so I’m making a card game-- and the way that it’s set up, currently, is that when I want to create a card, the call goes to the card manager with an id-- this id being the specific card in question. The card is fetched (the data, I should say) and the prefab is created. This is nice because I can just supply a random id and it will give me a random card. The problem I’ve run into is (theoretically) initializing these cards as enemies.
When the object is created, sometimes I’ll know which card I’m calling (and therefore, which specific class it should be-- ie. Arcanist, Fire Mage, etc) and sometimes I won’t. I’ve had to settle with the less-than-ideal situation of using GetComponent(“scriptname”) to add the appropriate script behavior, but I don’t like the idea of GetComponent having to do a string search, as I feel like this call could get costly (I also don’t like the idea of having a million unique scripts per unique enemy, but I don’t see a way around that). Is there a more efficient, or more OOP to do this? Should I even attach a component?
The idea behind attaching a component with the specific class script was so that I could have a parent class, EnemyAI, run virtual methods like OnHit(), or PostTurnEffect() and then override child methods could be called instead (so that each enemy exhibits specific behavior) but I’m starting to question whether that’s the best way to go about it.
Any ideas? Surely this has been done before?