daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Apr 17th, 2013 336 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class NetworkCharacter : Photon.MonoBehaviour
  4. {
  5.        
  6.        
  7.                
  8.         MouseLook mouselook;
  9.         FPSInputController controller;
  10.         CharacterMotor charactermotor;
  11.         CharacterController controller2;
  12.  
  13.     void Awake()
  14.     {
  15.                 mouselook = GetComponent<MouseLook>();
  16.                 controller = GetComponent<FPSInputController>();
  17.                 charactermotor = GetComponent<CharacterMotor>();
  18.                 controller2 = GetComponent<CharacterController>();
  19.                        
  20.        
  21.  
  22.         if (photonView.isMine)
  23.         {
  24.                         Debug.Log ("HELLO!!!");
  25.             //MINE: local player, simply enable the local scripts
  26.             mouselook.enabled = true;
  27.                         controller.enabled = true;
  28.                         charactermotor.enabled = true;
  29.                         controller2.enabled = true;
  30.         }
  31.         else
  32.         {  
  33.                         Debug.Log ("Hello AGAIN!");
  34.             /*mouselook.enabled = false;
  35.                         controller.enabled = false;
  36.                         charactermotor.enabled = false;
  37.                         controller2.enabled = false;*/
  38.         }
  39.  
  40.         gameObject.name = gameObject.name + photonView.viewID;
  41.     }
  42.        
  43.        
  44.     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
  45.     {
  46.         if (stream.isWriting)
  47.         {
  48.             //We own this player: send the others our data
  49.             //stream.SendNext((int)controllerScript._characterState);
  50.             stream.SendNext(transform.position);
  51.             stream.SendNext(transform.rotation);
  52.         }
  53.         else
  54.         {
  55.             //Network player, receive data
  56.             //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
  57.             correctPlayerPos = (Vector3)stream.ReceiveNext();
  58.             correctPlayerRot = (Quaternion)stream.ReceiveNext();
  59.         }
  60.     }
  61.  
  62.     private Vector3 correctPlayerPos = Vector3.zero; //We lerp towards this
  63.     private Quaternion correctPlayerRot = Quaternion.identity; //We lerp towards this
  64.  
  65.     void Update()
  66.     {
  67.         if (!photonView.isMine)
  68.         {
  69.             //Update remote player (smooth this, this looks good, at the cost of some accuracy)
  70.             transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
  71.             transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
  72.         }
  73.     }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top