Advertisement
kadyr

Untitled

Sep 4th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 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 Send()
  41. {
  42. if (string.IsNullOrEmpty(chatInput.text))
  43. {
  44. return;
  45. }
  46. if(Input.GetKeyDown(KeyCode.Return))
  47. {
  48. photonView.RPC("ShowMessage", RpcTarget.All, PhotonNetwork.NickName + ":" +
  49. chatInput.text);
  50. chatInput.text = "";
  51. }
  52. }
  53. public void LeaveRoom()
  54. {
  55. PhotonNetwork.LeaveRoom();
  56. }
  57. public override void OnLeftRoom()
  58. {
  59. SceneManager.LoadScene(0);
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement