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:

     // this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector)
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         // Always send transform (depending on reliability of the network view)
         if (stream.isWriting)
         {
             Vector3 pos = transform.localPosition;
             Quaternion rot = transform.localRotation;
             stream.Serialize(ref pos);
             stream.Serialize(ref rot);
         }
         // When receiving, buffer the information
         else
         {
             // Receive latest state information
             Vector3 pos = Vector3.zero;
             Quaternion rot = Quaternion.identity;
             stream.Serialize(ref pos);
             stream.Serialize(ref rot);

             lastMovement = (pos - latestCorrectPos) / (Time.time - lastTime);

             lastTime = Time.time;
             latestCorrectPos = pos;

             transform.position = latestCorrectPos;
         }
     }