Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- public class NetworkedPlayer : MonoBehaviourPunCallbacks
- {
- private GameObject spawnedCameraRig;
- private GameObject _temp;
- private NetworkManager _name;
- public GameObject body;
- public Transform _playerLocal;
- public Transform _playerGlobal;
- private Vector3 receivedHeadPos;
- private Quaternion receivedHeadRota;
- void Start()
- {
- if (photonView.IsMine)
- {
- this.transform.parent = null;
- _temp = GameObject.Find("Discovery One");
- _name = _temp.GetComponent<NetworkManager>();
- body = GameObject.Find("Avatar_" + _name.number + "(Clone)");
- spawnedCameraRig = (GameObject)Instantiate(Resources.Load("Player" + _name.number + "/Camera_" + _name.number), new Vector3(0f, 0f, 0f), Quaternion.identity);
- _playerGlobal = GameObject.Find("Camera_" + _name.number + "(Clone)").transform;
- _playerLocal = _playerGlobal.Find("TrackingSpace/CenterEyeAnchor");
- if(_playerLocal == null)
- {
- _playerLocal = _playerGlobal.Find("CenterEyeAnchor");
- }
- this.transform.SetParent(_playerLocal);
- this.transform.position = Vector3.zero;
- }
- }
- void Update()
- {
- if (photonView.IsMine)
- {
- body.transform.position = new Vector3(_playerLocal.transform.position.x, _playerLocal.transform.position.y + 0.35f, _playerLocal.transform.position.z);
- }
- this.transform.position = Vector3.Lerp(this.transform.position, receivedHeadPos, 0.1f);
- this.transform.rotation = Quaternion.Lerp(this.transform.rotation, receivedHeadRota, 0.1f);
- }
- private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
- {
- if (stream.IsWriting)
- {
- Debug.Log("im sending alot of data!");
- stream.SendNext(_playerLocal.position);
- stream.SendNext(_playerLocal.rotation);
- }
- else
- {
- Debug.Log("Im receiving alot of data!");
- receivedHeadPos = (Vector3)stream.ReceiveNext();
- receivedHeadRota = (Quaternion)stream.ReceiveNext();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement