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 ConnectToNameServer()
     {
         if (PhotonHandler.AppQuits)
         {
             Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
             return false;
         }

         IsUsingNameServer = true;
         this.CloudRegion = CloudRegionCode.none;

         if (this.State == global::PeerState.ConnectedToNameServer)
         {
             return true;
         }

         #if RHTTP
         string address = (this.UsedProtocol == ConnectionProtocol.RHttp) ? this.NameServerAddressHttp : this.NameServerAddress;
         #else
         string address = this.NameServerAddress;
         #endif

         if (!address.Contains(":"))
         {
             int port = 0;
             ProtocolToNameServerPort.TryGetValue(this.UsedProtocol, out port);
             address = string.Format("{0}:{1}", address, port);
             Debug.Log("Server to connect to: " + address + " settings protocol: " + PhotonNetwork.PhotonServerSettings.Protocol);
         }
         if (!base.Connect(address, "ns"))
         {
             return false;
         }

         this.State = global::PeerState.ConnectingToNameServer;
         return true;
     }