Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5.  
  6. public class NetworkManager : MonoBehaviourPunCallbacks
  7. {
  8.  
  9. string gameVersion = "1";
  10.  
  11. // Start is called before the first frame update
  12. void Awake()
  13. {
  14. // #Critical
  15. // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
  16. PhotonNetwork.AutomaticallySyncScene = true;
  17. }
  18.  
  19. void Start()
  20. {
  21. Debug.Log("This is Start");
  22. Connect();
  23. }
  24.  
  25. public void Connect()
  26. {
  27. // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
  28. if (PhotonNetwork.IsConnected)
  29. {
  30. Debug.Log("In the If-statement where PhotonNetwork.Isconnected, we will therefore create Room1");
  31. // #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnJoinRandomFailed() and we'll create one.
  32. PhotonNetwork.CreateRoom("Room1");
  33. }
  34. else
  35. {
  36. Debug.Log("We are in the else of connected");
  37. // #Critical, we must first and foremost connect to Photon Online Server.
  38. PhotonNetwork.GameVersion = gameVersion;
  39. //During Start() we call our public function Connect() which calls this method. The important information to remember here is that this method is the starting point to connect to Photon Cloud.
  40. PhotonNetwork.ConnectUsingSettings();
  41. }
  42. }
  43.  
  44. public override void OnConnectedToMaster()
  45. {
  46. Debug.Log("PUN Basic Tutorial/Launcher: OnConnectedToMaster() was called by PUN");
  47. // #Critical, The first thing we try to do is to join an existing room, If there is, good, else, we'll be called back with OnJoinRandomFailed()
  48. PhotonNetwork.JoinRandomRoom();
  49. }
  50.  
  51.  
  52. public override void OnJoinRandomFailed(short returnCode, string message)
  53. {
  54.  
  55. Debug.Log("We are here!");
  56. // #Critical, we failed to join a random room, maybe none exists or they are all full. No worries, we create a new room.
  57. PhotonNetwork.CreateRoom("Room1");
  58. }
  59.  
  60. public override void OnJoinedRoom()
  61. {
  62. Debug.Log(PhotonNetwork.PlayerList.Length);
  63. Debug.Log("PUN Basics Tutorial/Launcher: OnJoinedRoom() called by PUN. Now this client is in a room.");
  64.  
  65.  
  66.  
  67. //#Critical, we only load if we are the first player, else we rely on 'PhotonNetwork.AutomaticallySyncScene' to sync our instance scene
  68.  
  69. int number = PhotonNetwork.CurrentRoom.PlayerCount;
  70. Debug.Log("WE ARE CoNNCTED BITCH");
  71. if(PhotonNetwork.IsMasterClient) {
  72. Debug.Log("IM THE FUCKING MASTER CLIENT BBIATCH!");
  73. PhotonNetwork.Instantiate("Player_" + number, new Vector3(0f, 0f, 0f), new Quaternion(0f, 180f, 0f, 0f));
  74. // We need to insert something to control here.
  75. //Meaning this is suppose to be loading
  76. // PhotonNetwork.LoadLevel("herewefuckingo");
  77. }else if(!PhotonNetwork.IsMasterClient)
  78. {
  79. Debug.Log("IM JUST A LITTLE BITCH No.2");
  80. PhotonNetwork.Instantiate("Player_" + number, new Vector3(0f, 0f, 0f), new Quaternion(0f, 180f, 0f, 0f));
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement