EDIT: NEVERMIND! I found it! The error was in the OnPhotonSerializeView function; I didn’t change the transform.rotation and transform.position values to realRotation and realPosition!
Hi Unity. I’m having a bit of a problem with my script. If I have two clients running at the same time, the other player on the first client is shown to have reset their position, going back to (0, 0, 0). This is my code:
using UnityEngine;
using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (photonView.isMine) {
//Do nothing
}
else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
Debug.Log ("View is Serialized");
if(stream.isWriting) {
//Our player
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else {
//someone else's player
transform.position = (Vector3)stream.ReceiveNext();
transform.rotation = (Quaternion)stream.ReceiveNext();
}
}
}