Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5.  
  6. public class NetworkedPlayer : MonoBehaviourPunCallbacks
  7. {
  8.  
  9. private GameObject spawnedCameraRig;
  10. private GameObject _temp;
  11. private NetworkManager _name;
  12. public GameObject body;
  13.  
  14. public Transform _playerLocal;
  15. public Transform _playerGlobal;
  16.  
  17. private Vector3 receivedHeadPos;
  18. private Quaternion receivedHeadRota;
  19.  
  20. void Start()
  21. {
  22. if (photonView.IsMine)
  23. {
  24.  
  25. this.transform.parent = null;
  26.  
  27. _temp = GameObject.Find("Discovery One");
  28. _name = _temp.GetComponent<NetworkManager>();
  29.  
  30.  
  31. body = GameObject.Find("Avatar_" + _name.number + "(Clone)");
  32. spawnedCameraRig = (GameObject)Instantiate(Resources.Load("Player" + _name.number + "/Camera_" + _name.number), new Vector3(0f, 0f, 0f), Quaternion.identity);
  33. _playerGlobal = GameObject.Find("Camera_" + _name.number + "(Clone)").transform;
  34. _playerLocal = _playerGlobal.Find("TrackingSpace/CenterEyeAnchor");
  35.  
  36.  
  37. if(_playerLocal == null)
  38. {
  39. _playerLocal = _playerGlobal.Find("CenterEyeAnchor");
  40. }
  41.  
  42. this.transform.SetParent(_playerLocal);
  43. this.transform.position = Vector3.zero;
  44.  
  45. }
  46. }
  47. void Update()
  48. {
  49.  
  50.  
  51.  
  52.  
  53. if (photonView.IsMine)
  54. {
  55. body.transform.position = new Vector3(_playerLocal.transform.position.x, _playerLocal.transform.position.y + 0.35f, _playerLocal.transform.position.z);
  56.  
  57. }
  58. this.transform.position = Vector3.Lerp(this.transform.position, receivedHeadPos, 0.1f);
  59. this.transform.rotation = Quaternion.Lerp(this.transform.rotation, receivedHeadRota, 0.1f);
  60. }
  61. private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
  62. {
  63. if (stream.IsWriting)
  64. {
  65. Debug.Log("im sending alot of data!");
  66.  
  67. stream.SendNext(_playerLocal.position);
  68. stream.SendNext(_playerLocal.rotation);
  69.  
  70.  
  71. }
  72. else
  73. {
  74. Debug.Log("Im receiving alot of data!");
  75.  
  76. receivedHeadPos = (Vector3)stream.ReceiveNext();
  77. receivedHeadRota = (Quaternion)stream.ReceiveNext();
  78.  
  79. }
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement