What is the best way to create scripts hierarchy?

Hello there.
There is question I would like to ask more advanced developers.
I’m kind of a beginner in Unity and C#, but have successfully done the create with code tutorial and I’m really determined to learn more and more about the programming.
I am not asking for finished code, just to point me in the right direction. Working now on a personal project, I come to the realization that I have to think about the hierarchy of the scripts in my project.

What I learned is that is it usually bad experience to create dependencies between scripts, search for components and other scripts via GameObjects etc. And it is much better to use Events, EventBrokers etc. Question is how should I put all my game together.

Thing is, in my game I will have multiple Enemies, so first of all I learned about Scriptable Objects (SO next), and created a SO for the base class Enemy. It will store all the basic features of the class Enemy. Also thinking ahead I created GameObjects I will attach this SO’s and a script that will assign all the parameters from the SO to the prefab (in my case it will be a prefab for each enemy). This way I don’t need to assign them for all enemies myself.

1.) Question is for now, what would be the best way to achieve more functionality. Should I create another script which will contain the basic behavior for all enemies, and then via SO I will choose the behavior that is possible for a concrete kind of enemy. And should I create Interfaces like IKillable and IDieable to manage the basic functions that my enemies will be making?

2.) Also will it be good to create a GameMenu scene that will be loaded forever to store the menu, and a scene to store all the game interactions?

3.) What is the best way to save enemies? (Think of HOMAM3 or FF) Enemy Hero has 3 stacks of prefabs of different enemies. So should I use dictionaries to best access them? And what would be the best way to store the amount of enemies in a stack and the type of enemy. Drop Items, DamageTypes, Skills etc.

Again, I would be very thankful if you all would just point me in the right direction, I’m getting really hyped to learn all this stuff! Learning about SO itself was really awesome, and after two days I finally get it all to work in the editor, that was huge. Maybe its a long period for a so simple for someone topic, but again, all this is really new for me, and I like to work with this very much after my regular working day. :smile:

Thank you all. :slight_smile:

The best way? I would estimate there are about 10,000 fairly active users posting on this forum, so you will probably get about 10,000 different best ways.

As a teacher of game programming, I always tell my students that, if writing a piece of code will get you an answer, write that code and get your answer. In your case, you don’t want to know what will happen when you run some C#; you are asking how to organize and structure your projects. But that is just the same thing in a more abstract way. To get your answer, pick one approach and use it for a while. Then, with what you have learned from that experience, try another approach. Over time, you’ll find your choices converge to a style that works best for you (which will get us to 10,001 answers).

Whatever you do, don’t let “analysis paralysis” stop you from creating. “Perfect” is not the standard you must meet. “Good enough” will always do.

2 Likes

Hello.
Thank you very much for your reply. You are indeed right. I was just afraid I would do some big mistakes (of course I will make many of them anyway), and wanted to make sure that I’m on the right path. I will continue working and in time I will find by myself what is the best way for me. Thanks.
Greetings from Ukraine. :slight_smile:

6994388--826175--upload_2021-3-31_13-53-47.png