- Home /
Script structuring?
I've finished coding a scoring system for my simple game, but I'm wondering how to structure the scoring system itself to make it fit more nicely into the Unity design. Seeing Unity is designed to be bottom-up (Entities owns Logic):
should I have the entities register themselves with a score keeper (another entity), or
should I have a score keeper to keep track all entities?
If it helps, the game is where the player controls a square, and has to avoid dots that are flying everywhere on the screen. Whenever the a dot exit the screen, the score goes up.
EDIT: the dots are spawned by a spawn manager if that helps a bit
Answer by kacyesp · Sep 02, 2014 at 12:23 PM
If you can do it efficiently, it makes more sense for the score keeper to keep track of the entities. But if it's more efficient for the entities to register themselves with the score keeper, then do it that way.
Not so much about efficiency, more about confor$$anonymous$$g to coding standards. (I really hate dirty code, and badly designed program structures.)
If you don't care about efficiency then the score keeper should keep track of the entities, and the entities should not even know the score keeper exists.
Answer by aman_jha · Sep 02, 2014 at 12:26 PM
How are you detecting the dots that exit the screen? I'm assuming you use colliders. On the colliders, attach a script on it that references a script on an empty gameobject. That gameobject should be called the Game Controller. Have a script specific to said GameController. When the collider detects a dot, it should call a function on the GameController which controls the score.
If you need any code feel free to comment on this, just make sure you tell me your language ;)
no colliders, i'm just using the main camera view port for this (checking whether the camera can see it still - since the dots spawn in the middle of the screen). I'm using c#.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162122im_/https://answers.unity.com/themes/thub/images/avi.jpg)