Advertisement
kadyr

Untitled

Sep 11th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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. void Log(string message)
  17. {
  18. Debug.Log(message);
  19. ChatText.text += "\n";
  20. ChatText.text += message;
  21. }
  22.  
  23. public override void OnPlayerEnteredRoom(Player player)
  24. {
  25. Log(player.NickName + "Вошёл в комнату!");
  26. }
  27.  
  28. public override void OnPlayerLeftRoom(Player otherPlayer)
  29. {
  30. Log(otherPlayer.NickName + " вышел из комнаты");
  31. }
  32.  
  33. [PunRPC]
  34. public void ShowMessage(string message, PhotonMessageInfo info)
  35. {
  36. ChatText.text += "\n";
  37. ChatText.text += message;
  38. }
  39.  
  40. public void StartGame()
  41. {
  42. PhotonNetwork.LoadLevel(2);
  43. }
  44. public void Send()
  45. {
  46. if (string.IsNullOrEmpty(chatInput.text))
  47. {
  48. return;
  49. }
  50. if(Input.GetKeyDown(KeyCode.Return))
  51. {
  52. photonView.RPC("ShowMessage", RpcTarget.All, PhotonNetwork.NickName + ":" +
  53. chatInput.text);
  54. chatInput.text = "";
  55. }
  56. }
  57. public void LeaveRoom()
  58. {
  59. PhotonNetwork.LeaveRoom();
  60. }
  61. public override void OnLeftRoom()
  62. {
  63. SceneManager.LoadScene(0);
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement