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 PunPickupSimple(PhotonMessageInfo msgInfo)
     {
         // one of the messages might be ours
         // note: you could check "active" first, if you're not interested in your own, failed pickup-attempts.
         if (this.SentPickup && msgInfo.sender.isLocal)
         {
             if (this.gameObject.GetActive())
             {
                 // picked up! yay.
             }
             else
             {
                 // pickup failed. too late (compared to others)
             }
         }

         this.SentPickup = false;

         if (!this.gameObject.GetActive())
         {
             Debug.Log("Ignored PU RPC, cause item is inactive. " + this.gameObject);
             return;
         }


         // how long it is until this item respanws, depends on the pickup time and the respawn time
         double timeSinceRpcCall = (PhotonNetwork.time - msgInfo.timestamp);
         float timeUntilRespawn = SecondsBeforeRespawn - (float)timeSinceRpcCall;
         //Debug.Log("msg timestamp: " + msgInfo.timestamp + " time until respawn: " + timeUntilRespawn);

         if (timeUntilRespawn > 0)
         {
             // this script simply disables the GO for a while until it respawns.
             this.gameObject.SetActive(false);
             Invoke("RespawnAfter", timeUntilRespawn);
         }
     }