Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon.Pun;
- using UnityEngine.UI;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Photon.Realtime;
- using System.Collections.Generic;
- public class RoomManager : MonoBehaviourPunCallbacks
- {
- [SerializeField]
- private Text ChatText;
- [SerializeField]
- private InputField chatInput;
- void Log(string message)
- {
- Debug.Log(message);
- ChatText.text += "\n";
- ChatText.text += message;
- }
- public override void OnPlayerEnteredRoom(Player player)
- {
- Log(player.NickName + "Вошёл в комнату!");
- }
- public override void OnPlayerLeftRoom(Player otherPlayer)
- {
- Log(otherPlayer.NickName + " вышел из комнаты");
- }
- [PunRPC]
- public void ShowMessage(string message, PhotonMessageInfo info)
- {
- ChatText.text += "\n";
- ChatText.text += message;
- }
- public void Send()
- {
- if (string.IsNullOrEmpty(chatInput.text))
- {
- return;
- }
- if(Input.GetKeyDown(KeyCode.Return))
- {
- photonView.RPC("ShowMessage", RpcTarget.All, PhotonNetwork.NickName + ":" +
- chatInput.text);
- chatInput.text = "";
- }
- }
- public void LeaveRoom()
- {
- PhotonNetwork.LeaveRoom();
- }
- public override void OnLeftRoom()
- {
- SceneManager.LoadScene(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement