Referencing Objects -> Best Practices

Hello, Unity Community!

I’ve been a game developer and programmer going on 7+ years now, but only recently have starting developing my games in Unity. Regarding this, I have a few questions on what is considered a “best practice” for keeping track of and manipulating objects in the scene.

I have a parallax script, which translates multiple backgrounds across the screen at different speeds, to give the illusion of depth in a 2D environment.

So, my question is, would it be considered more formal if I attached a script to each background layer (foreground, middleground, background, etc.) to translate it, or would it be more efficient to have a single script and create different pointers referencing the different background game objects, and translating them that way?

My goal is basically to maintain a “low coupling, high cohesion” coding environment from the start, and seeing as I may have multiple “similar” objects (background layers as an example), I am not sure if it would be more efficient to create an attached script for each object, or keep them together in a single script.

Thank you for taking the time to read this and any who reply.




asking this question on the forums, it would indeed be more efficient to contain all of the scripting in a single file, rather than spread out over multiple files, as this reduces the amount of function calls and code needed to be parsed by Unity.