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 void OnGUI()
     {
         GUI.skin = this.Skin;
         GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
         {
             string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
             if (GUILayout.Button(label))
             {
                 this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
             }
         }
         GUILayout.EndArea();



         if (PhotonNetwork.inRoom)
         {
             int playerNr = PhotonNetwork.player.ID;
             string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
             string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
             GUILayout.Label(string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));

             foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
             {
                 playerNr = otherPlayer.ID;
                 playerIsMaster = otherPlayer.isMasterClient ? "(master)" : "";
                 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
                 GUILayout.Label(string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
             }

             if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
             {
                 GUILayout.Label("Join more clients to switch object-control.");
             }
         }
         else
         {
             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
         }
     }