Hey guys,
I am not sure if someone asked before about this but I didnt find it so…
We are creating a TD game with my classmate and I dont really know how to make several types of units ( with different hp, gold reward, special abilities, …). I created spawning system with certain amount of units and interval of spawning plus prefab of gameobject in one script and its all working. But the thing is I cant figure it out how to create class of units where will be every attribute that i can later connect to prefabs of every unit and connect it to spawning system as well.
I mean like tower shoot and hit one gameobject and the hp of the unit will decrease.
If I understand what you’re saying, you want to register new units with scripts that are responsible for interacting with them. So for example, a Tower needs to be aware of it’s targets even though they may not be immediately related.
This is a tricky subject, and there are a couple ways of solve it. My personal approach so far has been to use a singleton, but singletons are a fairly polarizing subject among programmers so don’t be surprised if I get criticised for this post.