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 PickupItemInit(double timeBase, float[] inactivePickupsAndTimes)
     {
         this.IsWaitingForPickupInit = false;

         // if there are no inactive pickups, the sender will send a list of 0 items. this is not a problem...
         for (int i = 0; i < inactivePickupsAndTimes.Length / 2; i++)
         {
             int arrayIndex = i*2;
             int viewIdOfPickup = (int)inactivePickupsAndTimes[arrayIndex];
             float timeUntilRespawnBasedOnTimeBase = inactivePickupsAndTimes[arrayIndex + 1];


             PhotonView view = PhotonView.Find(viewIdOfPickup);
             PickupItem pi = view.GetComponent();

             if (timeUntilRespawnBasedOnTimeBase <= 0)
             {
                 pi.PickedUp(0.0f);
             }
             else
             {
                 double timeOfRespawn = timeUntilRespawnBasedOnTimeBase + timeBase;

                 Debug.Log(view.viewID + " respawn: " + timeOfRespawn + " timeUntilRespawnBasedOnTimeBase:" + timeUntilRespawnBasedOnTimeBase + " SecondsBeforeRespawn: " + pi.SecondsBeforeRespawn);
                 double timeBeforeRespawn = timeOfRespawn - PhotonNetwork.time;
                 if (timeUntilRespawnBasedOnTimeBase <= 0)
                 {
                     timeBeforeRespawn = 0.0f;
                 }

                 pi.PickedUp((float) timeBeforeRespawn);
             }
         }
     }