I think your question is an excellent one. Basically…when you have many scripts or objects that all need to communicate with each other (or maybe one to many), how do you design this?
So, maybe it’s like you said in your first post.
You have a player, with its own script.
You have a pathfinding script, with its own script. It needs to know about all players/npcs in the game, buildings, whatever.
You have a save game script, which needs to know about player data and such.
What is a -good- way to design this, without creating a maintenance or performance nightmare?
With the pathfinding script, I would think it would need to know about all of your npcs, in order to control them. So effectively, each npcs should TELL the path finder about its existence.
So your pathfinder would be a single script that controls all npcs that it knows about. You could do this by creating an empty gameobject in your hierarchy, and add the path finding script as a component. Then have a reference in your npc scripts to that gameobject or the pathfinder script. When they start(), they could tell the pathfinder about their existence.
Couple of ways you could do this, and again, this approach is assuming the pathfinder just needs to know about your npcs, and that they don’t control much.
Or, you could just use the static class/singleton approach. There are some gotchas with using static classes…but I believe if you mostly use them as utility classes (like Mathf). If you wanted to have multiple pathfinding scripts, like a Cowardly AI or a MeleeAI or a RangedAI behaviors, you’d have to really think this through. But if you only needed one pathfinding script, EVER, yeah why not? But this thread is about communication, not as much about singleton/design patterns 
Basically, my approach would be to separate things into two groups:
- Controllers or Systems - Pathfinding, game saver, menu system, etc.
- Things that are controlled (entities)
Npcs and players are entities. They are controlled by the human on the end, or the pathfinding/ai controller. They also have data that is saved. Health, position, that sort of thing.
The controllers need to know about the entities. The entities don’t -really- need to know about the controllers, not really. All they need to do is when they run Start(), they need to tell the controllers…hey, here is a reference to me. From now on, you know about me. GameSaver, anytime you are told to save the game, you know me, and all my buddies, and the npcs, whatever, save our data. Do you thing, after I exit start() and tell you that I exist, I don’t care anymore. I’ve got my hands full responding to player keypresses and jumping around. So in the npc script Start() method, it might do this: ScriptController.AddNpc(this);
That way, you keep each thing only responsible for a very targetted function. Other than letting the controllers know that they exist, npcs and the player don’t have to worry about saving games, or pathfinding. It just happens, all they have to do is make sure that when they start, they tell the controllers a reference to them. The player should only be worried about player stuff, not all the other crap that happens in a game.
I hope this is helpful…and maybe someone else can point out some other suggestions, or flaws in my thought process. I’m sorta new at the game dev thing, but I do have good business programming experience, so take it for what it’s worth.
(As far as a singleton vs just giving everything a reference to other script components…I don’t know that I have a hard and fast rule (yet). If I have a class that like Mathf, and I know I won’t ever have more than one for math functions, yeah…make it a singleton or a static class. If it’s something I want to see details about in the inspector, I’d probably just create a gameobject in the hierarchy and attach the script to that gameobject, and drag to variable references in my prefabs.)
Again, I think you have a great question, I’d love input from others on this subject. I would love to see different approaches given a name, with some basic examples and discussions on why an approach is good, pros and cons, etc.
Anyone want to start an article on Unity Game Design Patterns? 