I'm creating a game that have multiples references to scripts, one to another.
For exemple:
- Controller script
- SomeBehavior script
- GUI script
My doubt enter when I can do two different things:
- In SomeBehavior access/edit GUI variable/function that I whant... Like:
1.1. variable = GameObject.Find("GuiTag").GetComponent< GUI script >();
variable.score.... and go on... - In SomeBehavior access/edit GUI variable/function by Controller.gui (gui a public variable on controller script)... Centralization all the base scripts to one, in that way, having less variables in the scripts, less memory (perraps)...
2.1. variable = GameObject.Find("ControllerTag").GetComponent< Controller script >();
variable.gui.score....
Which one is better?
GameObject.Findif you'll use them again,Findis a spendy call. As far as memory goes... you should probably read up on C#'s reference types. "Less variables in the scripts" has little-to-no relation to memory. - Jerdak