- Home /
What should a script contain?
Ok, this is a very basic question but I swear I searched and didn't find it asked before.
Say I want an "NPC" object to have 3 functions:
To walk around all the time
To do X when clicked
To die after Y minutes.
I know how to script all of these things, but what is better?
To include these 3 functions in a single script, or make a separate script for each?
I know it would work either way, but I don't know what the best way to do it would be, specially since I'm new to game development and am bad at seeing the big picture.
Thanks!
Answer by Apples_mmmmmmmm · Jul 31, 2012 at 06:18 AM
To me it makes more sense to create a script for each specific thing you are trying to attain. If you have multiple scripts for the things you listed then you could also utilize each script on an object that you may not need the other two scripts for. For example you may want to have a sign that when clicked on will display text, but functionality you probably don't want the sign to have is to be destroyed after a certain time, and you probably don't want it walking around all the time. If you only had one script, then you would have to either add more code or create another script specifically for the sign because the other script contains unneeded information. Keeping separate scripts for specific tasks will save you time in the long run. Of course, this is my personal opinion, and I'm sure others have may have different views.