Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. BtnMap.cs (odpalanie map)
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.SceneManagement;
  7.  
  8. public class BtnMap : MonoBehaviour {
  9.  
  10. JoinMenager JM;
  11.  
  12. void Start()
  13. {
  14. DontDestroyOnLoad(gameObject);
  15. JM = GetComponent<JoinMenager>();
  16. }
  17.  
  18. public void BtnMap1 ()
  19. {
  20. JM.Connect();
  21. SceneManager.LoadScene(4);
  22. }
  23.  
  24. public void BtnMap2 ()
  25. {
  26. JM.Connect();
  27. SceneManager.LoadScene(5);
  28. }
  29.  
  30. public void BtnMap3 ()
  31. {
  32. JM.Connect();
  33. SceneManager.LoadScene(6);
  34. }
  35. }
  36.  
  37.  
  38.  
  39.  
  40. JoinMenager (menadżer połączeń, odpowiada za łączenie z serwerem, odłączeniem itd)
  41.  
  42. using System.Collections;
  43. using System.Collections.Generic;
  44. using UnityEngine;
  45.  
  46. public class JoinMenager : Photon.MonoBehaviour
  47. {
  48.  
  49. void Update()
  50. {
  51. if (Input.GetKeyDown(KeyCode.Tab))
  52. Player.Debug2();
  53. }
  54.  
  55. public void Connect()
  56. {
  57. PhotonNetwork.ConnectUsingSettings("Alpha_EarlyAcces_June2019_0.0.1");
  58. }
  59.  
  60. void OnGUI()
  61. {
  62. GUI.Label(new Rect(0, 0, 200, 20), PhotonNetwork.connectionStateDetailed.ToString());
  63. }
  64.  
  65. void OnJoinedLobby()
  66. {
  67. PhotonNetwork.JoinRandomRoom();
  68. }
  69.  
  70. void OnJoinedRandomJoinFailed()
  71. {
  72. PhotonNetwork.CreateRoom(null);
  73. }
  74.  
  75. void OnPlayerConnected(PhotonPlayer pp)
  76. {
  77. if (PhotonNetwork.isMasterClient)
  78. {
  79. photonView.RPC("PlayerJoined", PhotonTargets.AllBuffered, pp);
  80. }
  81. }
  82.  
  83. [PunRPC]
  84. void PlayerJoined(PhotonPlayer pp)
  85. {
  86. Player player = new Player();
  87. player.nick = pp.NickName;
  88. player.pp = pp;
  89. Player.players.Add(player);
  90. }
  91.  
  92. [PunRPC]
  93. void PlayerDisconnected(PhotonPlayer pp)
  94. {
  95.  
  96. }
  97.  
  98. void OnCreatedRoom()
  99. {
  100. photonView.RPC("PlayerJoined", PhotonTargets.AllBuffered, PhotonNetwork.player);
  101. }
  102. }
  103.  
  104.  
  105.  
  106.  
  107. Player.cs (Lista graczy)
  108.  
  109. using System.Collections;
  110. using System.Collections.Generic;
  111. using UnityEngine;
  112.  
  113. public class Player
  114. {
  115. public string nick = "NicknameNULL";
  116. public PhotonPlayer pp;
  117.  
  118. public static List<Player> players = new List<Player>();
  119.  
  120. public static void Debug2()
  121. {
  122. Debug.Log("Debug playerlist! Count of player: " + players.Count + " all players: ");
  123.  
  124. foreach (var player in players)
  125. {
  126. Debug.Log(player.nick + ", ");
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement