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.insideLobby)
         {
             // this feature is only available on the Master Client. Check either: insideLobby or
             // PhotonNetwork.connectionStateDetailed == PeerState.Authenticated or
             // PhotonNetwork.connectionStateDetailed == PeerState.JoinedLobby

             // for simplicity (and cause we know we WILL join the lobby, we can just check that)
             return;
         }


         GUILayout.BeginArea(GuiRect);

         GUILayout.Label("Your (random) name: " + PhotonNetwork.playerName);
         GUILayout.Label("Your friends: " + string.Join(", ",this.friendListOfSomeCommunity));


         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Find Friends"))
         {
             PhotonNetwork.FindFriends(this.friendListOfSomeCommunity);
         }
         if (GUILayout.Button("Create Room"))
         {
             PhotonNetwork.CreateRoom(null); // just a random room
         }
         GUILayout.EndHorizontal();


         if (PhotonNetwork.Friends != null)
         {
             foreach (FriendInfo info in PhotonNetwork.Friends)
             {
                 GUILayout.BeginHorizontal();
                 GUILayout.Label(info.ToString());
                 if (info.IsInRoom)
                 {
                     if (GUILayout.Button("join"))
                     {
                         PhotonNetwork.JoinRoom(info.Room);
                     }
                 }
                 GUILayout.EndHorizontal();
             }
         }

         GUILayout.EndArea();
     }