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 DestroyPlayerObjects(int playerId, bool localOnly)
     {
         if (playerId <= 0)
         {
             Debug.LogError("Failed to Destroy objects of playerId: " + playerId);
             return;
         }

         if (!localOnly)
         {
             // clean server's Instantiate and RPC buffers
             this.OpRemoveFromServerInstantiationsOfPlayer(playerId);
             this.OpCleanRpcBuffer(playerId);

             // send Destroy(player) to anyone else
             this.SendDestroyOfPlayer(playerId);
         }

         // locally cleaning up that player's objects
         HashSet playersGameObjects = new HashSet();
         foreach (PhotonView view in this.photonViewList.Values)
         {
             if (view.CreatorActorNr == playerId)
             {
                 playersGameObjects.Add(view.gameObject);
             }
         }

         // any non-local work is already done, so with the list of that player's objects, we can clean up (locally only)
         foreach (GameObject gameObject in playersGameObjects)
         {
             this.RemoveInstantiatedGO(gameObject, true);
         }

         // with ownership transfer, some objects might lose their owner.
         // in that case, the creator becomes the owner again. every client can apply this. done below.
         foreach (PhotonView view in this.photonViewList.Values)
         {
             if (view.ownerId == playerId)
             {
                 view.ownerId = view.CreatorActorNr;
                 //Debug.Log("Creator is: " + view.ownerId);
             }
         }
     }