I’d like to know what’s the best way to proceed. I’m following a tutorial in which you build a game where you dodge boxes. So far so good.
Here’s the thing, the “Box” script only destroys the box if it goes too far Y.
I have another script, “GameManager”, that deals with the spawning of Boxes. Now, what I’d like to do, is increase the score whenever the boxes are destroyed by the Box method, because it would mean the player avoided them.
So, what’s the best way to do so here ? I’ve asked Claude, and it’s telling me to add an event “OnBoxDestroyed”, withing the box script. Is that something you’re supposed to do ? I could easily add the score to the Box script and be done with it, but I’d like to do things right. I believe it’s better in the GameManager.
So, here’s the thing: there’s no right answer here. It depends on your game, and what gets you to your goal the quickest. I’ve fallen prey to this endless ‘right way to code’ soooo many times it’s not even funny.
At the end of the day, the code is written to serve the game, not the other way around. If it’s quicker to test things out with a quick-and-dirty function on the Box script, then go for it! If you think adding it to the GameManager is quicker, then that’s the way to go.
I think you’re currently updating the score from the GameManager itself, is that right? What if you had a different game object that handled the score? How would that structure be different/beneficial? Cause then maybe you could add a BoxManager script that can have a reference in the ScoreManager script and that could be notified of box deletions and update the score. This way you would ‘decouple’ the GameManager from the score entirely. But what purpose would it serve when the game itself still functions the same. You just extended your development time for no apparent reason.
There’s a million ways to solve any problem. When in prototyping phase, the quicker you get things done, the quicker they get tested and changed. So, for right now, I think quick-and-dirty is the right way to goo about it. When you’re finally out of prototyping, you’ll know what the right way is, because you will know the game’s structure inside out. Until then, keep hacking things together and taking them apart!