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 OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if (stream.isWriting)
         {
             Vector3 pos = transform.localPosition;
             Quaternion rot = transform.localRotation;
             stream.Serialize(ref pos);
             stream.Serialize(ref rot);
         }
         else
         {
             // Receive latest state information
             Vector3 pos = Vector3.zero;
             Quaternion rot = Quaternion.identity;

             stream.Serialize(ref pos);
             stream.Serialize(ref rot);

             latestCorrectPos = pos; // save this to move towards it in FixedUpdate()
             onUpdatePos = transform.localPosition; // we interpolate from here to latestCorrectPos
             fraction = 0; // reset the fraction we alreay moved. see Update()

             transform.localRotation = rot; // this sample doesn't smooth rotation
         }
     }