Advertisement
kadyr

Untitled

Sep 25th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. using Photon.Pun;
  2. using UnityEngine.UI;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using Photon.Realtime;
  6. using System.Collections.Generic;
  7.  
  8. public class RoomManager : MonoBehaviourPunCallbacks
  9. {
  10. [SerializeField]
  11. private Text ChatText;
  12.  
  13. [SerializeField]
  14. private InputField chatInput;
  15.  
  16. [SerializeField]
  17. private GameObject startButton;
  18. private void Start()
  19. {
  20. if (!PhotonNetwork.IsMasterClient)
  21. {
  22. startButton.SetActive(false);
  23. }
  24. }
  25. void Log(string message)
  26. {
  27. Debug.Log(message);
  28. ChatText.text += "\n";
  29. ChatText.text += message;
  30. }
  31.  
  32. public override void OnPlayerEnteredRoom(Player player)
  33. {
  34. Log(player.NickName + "Вошёл в комнату!");
  35. }
  36.  
  37. public override void OnPlayerLeftRoom(Player otherPlayer)
  38. {
  39. if(PhotonNetwork.IsMasterClient)
  40. startButton.SetActive(true);
  41. Log(otherPlayer.NickName + " вышел из комнаты");
  42. }
  43.  
  44. [PunRPC]
  45. public void ShowMessage(string message, PhotonMessageInfo info)
  46. {
  47. ChatText.text += "\n";
  48. ChatText.text += message;
  49. }
  50.  
  51. public void StartGame()
  52. {
  53. PhotonNetwork.LoadLevel(2);
  54. }
  55. public void Send()
  56. {
  57. if (string.IsNullOrEmpty(chatInput.text))
  58. {
  59. return;
  60. }
  61. if(Input.GetKeyDown(KeyCode.Return))
  62. {
  63. photonView.RPC("ShowMessage", RpcTarget.All, PhotonNetwork.NickName + ":" +
  64. chatInput.text);
  65. chatInput.text = "";
  66. }
  67. }
  68. public void LeaveRoom()
  69. {
  70. PhotonNetwork.LeaveRoom();
  71. }
  72. public override void OnLeftRoom()
  73. {
  74. SceneManager.LoadScene(0);
  75. }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement