반응형
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
using Hashtable = ExitGames.Client.Photon.Hashtable;
public class NetworkManager : MonoBehaviourPunCallbacks
{
public override void OnJoinedRoom()
{
statusText.text = "방에 참가하였습니다.";
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "RoomState", "Waiting" } });
PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "Master", PlayerPrefs.GetString("NickName") } });
PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "Number", 123 } });
}
}
void LoadRoomState() //방 상태 불러오기
{
if (PhotonNetwork.InRoom)
{
Hashtable ht = PhotonNetwork.CurrentRoom.CustomProperties;
switch (ht["RoomState"])
{
case "Waiting":
Debug.Log("방이 대기중입니다.");
break;
case "Play":
Debug.Log("방이 게임중입니다. 다음 게임부터 참여 가능합니다.");
break;
default:
break;
}
}
}
void UpdateRoomState() //방 상태 변경하기
{
if(PhotonNetwork.InRoom)
{
if(PhotonNetwork.IsMasterClient)
{
PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "RoomState", "Playing" } });
}
}
}
}
반응형