So i used what i learned from your Merry Fragmas m-player tutorials, and used it as the bases to get my little learning game to work.
The issue i am having is that the players rotation is not syncing over. View video to see what is happening to me in game.
using UnityEngine;
using System.Collections;
public class PlayerNetworkMover : Photon.MonoBehaviour {
public delegate void Respawn(float time);
public event Respawn RespawnMe;
Vector3 position;
Quaternion rotation;
float smoothing = 10f;
float health = 100f;
bool idle = false;
bool run = false;
bool initialLoad = true;
Animator anim;
void Start ()
{
anim = GetComponentInChildren<Animator> ();
if(photonView.isMine)
{
GetComponent<AxisPlayerMove>().enabled = true;
GetComponentInChildren<ARPGCameraController>().enabled = true;
foreach(Camera cam in GetComponentsInChildren<Camera>())
cam.enabled = true;
}
else{
StartCoroutine("UpdateData");
}
}
IEnumerator UpdateData()
{
if(initialLoad)
{
initialLoad = false;
transform.position = position;
transform.rotation = rotation;
}
while(true)
{
transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing);
anim.SetBool ("idle", idle);
anim.SetBool ("run", run);
yield return null;
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(health);
stream.SendNext(anim.GetBool ("idle"));
stream.SendNext(anim.GetBool ("run"));
}
else
{
position = (Vector3)stream.ReceiveNext();
rotation = (Quaternion)stream.ReceiveNext();
health = (float)stream.ReceiveNext();
idle = (bool)stream.ReceiveNext();
run = (bool)stream.ReceiveNext();
}
}
[RPC]
public void GetShot(float damage)
{
health -= damage;
if(health <= 0 && photonView.isMine)
{
if(RespawnMe != null)
RespawnMe(3f);
PhotonNetwork.Destroy (gameObject);
}
}
}