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()
     {
         if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
         {
             return;
         }

         GUILayout.BeginArea(GuiRect);

         GUILayout.Label("In-Game");
         GUILayout.Label("For simplicity, this demo just shows the players in this room. The list will expand when more join.");
         GUILayout.Label("Your (random) name: " + PhotonNetwork.playerName);
         GUILayout.Label(PhotonNetwork.playerList.Length + " players in this room.");
         GUILayout.Label("The others are:");
         foreach (PhotonPlayer player in PhotonNetwork.otherPlayers)
         {
             GUILayout.Label(player.ToString());
         }

         if (GUILayout.Button("Leave"))
         {
             PhotonNetwork.LeaveRoom();
         }
         GUILayout.EndArea();
     }