Newbie trying to undestand unity
Hi all My name is stew I am trying to teach my self Unity and making some progress. :) However I have a question regarding object orientated programming; I am current following the Space Shooter tutorial and I am scripting the asteroid What I think I know so far: If an object is required to do something, it must have a script attached to it. From what I understand the script is where you write code to access events and create functions associated with the object the script is link to. My Question: Why would you need to attach multiple scripts to an object when you could write all the code in one script?
Answer by Addyarb · Sep 02, 2015 at 12:22 AM
Organization and ease-of-use is the answer to this one. The compiler more-or-less views everything on the object as a single script, but separating scripts by their relative functions (i.e. moving, inventory, animation) helps simplify debugging should you have something wrong with your code.
Is it necessary? Absolutely not. Some people work better with consolidating all of their methods/functions into one giant script. However, Unity staff will typically discourage this from what I've seen in their live lessons/tutorials.
Another less important factor is naming of variables. If you have the speed of your walking, speed of your flying, speed of your camera, etc. all in one script, you'd have to make the names longer and more descriptive - whereas if they were in the "CameraScript" class or the "AnimationParameters" class, you wouldn't have to guess at which speed you were working with.
Good luck with your game programming adventure! Watching the tutorials is the most valuable way to spend your time without question.
I agree with this answer if you weren't sure if it was correct its all really just for organisation