I am gravitating toward two different ways of scripting my game controllers in Unity, and was just wondering which is higher performance, and which is more maintainable as a project grows:
Method 1 is “Through inspector assignable references.” as described in Unity Script Reference - Overview: Accessing Other Game Objects. So every script that needs to talk to my controller has a slot like this and I drag and drop the gameobject into it:
var controller : Controller;
Method 2 is by using the static keyword and making like a singleton that can be referred to from anywhere via Controller.instance :
static var instance : Controller;
function Awake()
{
instance = this;
}
OK so Method 1 involves a lot of drag and drop to keep all the connections setup in the Editor. However, at runtime isn’t this the most efficient way to setup connections between scripts?
Method 2 involves global variables, which in Javascript are bad performing because of how scoping works. However in Unity Javascript, since it’s getting compiled at runtime or AOT for iphone, then there is no performance hit for using globals, correct?
I know there are variants of Method 1, like using a Find function in Awake() instead of dragging and dropping in the editor.
Alright, thanks for any suggestions!