private static void CCNetworkLog(ConCommandArgs args) { //Although here it's not relevant, you can ensure you are the server by checking if the NetworkServer is active. if (NetworkServer.active) { //Before we can Invoke our NetworkMessage, we need to make sure our centralized networkobject is spawned. // For doing that, we Instantiate the CentralNetworkObject, we obviously check if we don't already have one that is already instantiated and activated in the current scene. // Note : Make sure you Instantiate the gameobject, and not spawn it directly, it would get deleted otherwise on scene change, even with DontDestroyOnLoad. if (!_centralNetworkObjectSpawned) { _centralNetworkObjectSpawned = Object.Instantiate(CentralNetworkObject); NetworkServer.Spawn(_centralNetworkObjectSpawned); } //This readOnlyInstancesList is great for going over all players in general, // so it might be worth commiting to memory. foreach (NetworkUser user in NetworkUser.readOnlyInstancesList) { //Args.userArgs is a list of all words in the command arguments. MyNetworkComponent.Invoke(user, string.Join(" ", args.userArgs)); } } }
private void Awake() { _instance = this; }