Last active
October 1, 2020 07:27
-
-
Save haydenjameslee/499483f79620bb36607d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// For use with Photon and SteamVR | |
public class NetworkedPlayer : Photon.MonoBehaviour | |
{ | |
public GameObject avatar; | |
public Transform playerGlobal; | |
public Transform playerLocal; | |
void Start () | |
{ | |
Debug.Log("Player instantiated"); | |
if (photonView.isMine) | |
{ | |
Debug.Log("Player is mine"); | |
playerGlobal = GameObject.Find("[CameraRig]").transform; | |
playerLocal = playerGlobal.Find("Camera (head)"); | |
this.transform.SetParent(playerLocal); | |
this.transform.localPosition = Vector3.zero; | |
} | |
} | |
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) | |
{ | |
if (stream.isWriting) | |
{ | |
stream.SendNext(playerGlobal.position); | |
stream.SendNext(playerGlobal.rotation); | |
stream.SendNext(playerLocal.localPosition); | |
stream.SendNext(playerLocal.localRotation); | |
} | |
else | |
{ | |
this.transform.position = (Vector3)stream.ReceiveNext(); | |
this.transform.rotation = (Quaternion)stream.ReceiveNext(); | |
avatar.transform.localPosition = (Vector3)stream.ReceiveNext(); | |
avatar.transform.localRotation = (Quaternion)stream.ReceiveNext(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment