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:

     public bool Connect(string serverAddress, ServerConnection type)
     {
         if (PhotonHandler.AppQuits)
         {
             Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
             return false;
         }

         if (PhotonNetwork.connectionStateDetailed == global::PeerState.Disconnecting)
         {
             Debug.LogError("Connect() failed. Can't connect while disconnecting (still). Current state: " + PhotonNetwork.connectionStateDetailed);
             return false;
         }

         // connect might fail, if the DNS name can't be resolved or if no network connection is available
         bool connecting = base.Connect(serverAddress, "");
         if (connecting)
         {
             switch (type)
             {
                 case ServerConnection.NameServer:
                     State = global::PeerState.ConnectingToNameServer;
                     break;
                 case ServerConnection.MasterServer:
                     State = global::PeerState.ConnectingToMasterserver;
                     break;
                 case ServerConnection.GameServer:
                     State = global::PeerState.ConnectingToGameserver;
                     break;
             }
         }

         return connecting;
     }