Hello everyone,
i have quiet a large project in front of me with a lot of different script. Each script is called like that:
void Start() {
ScriptA a = GetComponent<ScriptA> ();
ScriptB b = GetComponent<ScriptB> ();
ScriptC c = GetComponent<ScriptC> ();
ScriptD d = GetComponent<ScriptD> ();
// ... and so on
a.AnyMethod();
b.AnyOtherMethod();
// ...
}
All of the Scripts are attached to the camera. Often the other scripts need the same list of Script references to operate.
Recently i read that the call GetComponent<> is quiet expensive. So i thought about why not make only one script (called “Vars”) that has the all the references stored in public variables. After that all the other scripts just need to get a single reference to the Vars script and can call the methods of the refereces. For exampe:
Vars v = GetComponent<Vars> ();
v.a.AnyMethod();
Is this more efficient to use the Vars class as the connection to the actual class that is needed?