Hi all, just a bit of advice needed here.
I am coding in C# and as my game is growing, I am adding many scripts to the myriad of game objects, but often they need to access scripts assigned to players, enemies etc.
So, simply put I am often re-typing the same code over and over in each script, namely the ones that reference player functionality.
An example would be the players control scripts and animator components.
I am forever having to remember to include the following sorts of code
// Declaring the var
GameObject player;
Animator anim;
// Then instantiating
player = GameObject.FindObjectWithTag("Player");
anim = player.GetComponent<Animator>();
Then I have to do this for each function, script etc.
Now, I don’t mind this, but it seems a little inefficient to me.
So, should I be putting these in one sort of control script that defines these as public statics so that I can reference them in a much simpler fashion?
I have never used statics before, so I am just after advice and opinions please