Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     /// The ping result can be overridden via PhotonNetwork.OverrideBestCloudServer(..)
     /// - Invalid AppId (calls: OnFailedToConnectToPhoton(). check exact AppId value)
     /// - Network issues (calls: OnFailedToConnectToPhoton())
     /// - Invalid region (calls: OnConnectionFail() with DisconnectCause.InvalidRegion)
     /// - Subscription CCU limit reached (calls: OnConnectionFail() with DisconnectCause.MaxCcuReached. also calls: OnPhotonMaxCccuReached())
     public static bool ConnectToBestCloudServer(string gameVersion)
     {
         if (PhotonServerSettings == null)
         {
             Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: " + PhotonNetwork.serverSettingsAssetFile);
             return false;
         }

         if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
         {
             return PhotonNetwork.ConnectUsingSettings(gameVersion);
         }

         networkingPeer.IsInitialConnect = true;
         networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);

         CloudRegionCode bestFromPrefs = PhotonHandler.BestRegionCodeInPreferences;
         if (bestFromPrefs != CloudRegionCode.none)
         {
             Debug.Log("Best region found in PlayerPrefs. Connecting to: " + bestFromPrefs);
             return networkingPeer.ConnectToRegionMaster(bestFromPrefs);
         }

         bool couldConnect = PhotonNetwork.networkingPeer.ConnectToNameServer();
         return couldConnect;
     }