์ฒ˜์Œ ๋ฐฉ ๋งŒ๋“œ๋Š” ์ปดํ“จํ„ฐ ์บ๋ฆญํ„ฐ๋Š” ์Šคํฐ์ด ์ •์ƒ์ ์œผ๋กœ ๋˜๋Š”๋ฐ , ๋‹ค์Œ์— ๋“ค์–ด์˜จ ์œ ์ €์˜ ์บ๋ฆญํ„ฐ ์Šคํฐ์ด ์•ˆ๋จ,ย  ์ด๊ฑฐ ์™œ์ด๋Ÿฌ๋Š”๊ฑฐ์ž„?

๊ด€๋ จ ์ฝ”๋“œ ์ „๋ฌธ์ด๊ณ  player ์ฝ”๋“œ๋Š” ํ•„์š” ์—†์ง€?
์Šคํฐํฌ์ธํŠธ๋Š” 2๊ฐœ๋กœ ์ž˜ ์žกํž˜.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;

public class PhotonManager : MonoBehaviourPunCallbacks
{
ย  ย  private readonly string gameVersion = "v1.0";
ย  ย  private string userId = "ysef";

ย  ย  private void Awake()
ย  ย  {
ย  ย  ย  ย  PhotonNetwork.GameVersion = gameVersion;
ย  ย  ย  ย  //๊ฒŒ์ž„ ๋ฒ„์ „์ง€์ •
ย  ย  ย  ย  PhotonNetwork.ConnectUsingSettings();
ย  ย  ย  ย  //์„œ๋ฒ„ ์ ‘์†

ย  ย  }

ย  ย  void Start()
ย  ย  {
ย  ย  ย  ย  Debug.Log("00.ํฌํ†ค๋งค๋‹ˆ์ € ์‹œ์ž‘");
ย  ย  ย  ย  PhotonNetwork.NickName = userId;

ย  ย  }
ย  ย  public override void OnConnectedToMaster()
ย  ย  {
ย  ย  ย  ย  Debug.Log("01.ํฌํ†ค์„œ๋ฒ„์— ์ ‘์†");
ย  ย  ย  ย  PhotonNetwork.JoinRandomRoom();
ย  ย  }
ย  ย  public override void OnJoinRandomFailed(short returnCode, string message)
ย  ย  {
ย  ย  ย  ย  Debug.Log("02. ๋žœ๋ค ๋ฃธ ์ ‘์† ์‹คํŒจ");

ย  ย  ย  ย  //๋ฃธ์†์„ฑ ์„ค์ •
ย  ย  ย  ย  RoomOptions ro = new RoomOptions();
ย  ย  ย  ย  ro.IsOpen = true;
ย  ย  ย  ย  ro.IsVisible = true;
ย  ย  ย  ย  ro.MaxPlayers = 20;

ย  ย  ย  ย  PhotonNetwork.CreateRoom("room_1", ro);
ย  ย  }

ย  ย  public override void OnCreatedRoom()
ย  ย  {
ย  ย  ย  ย  Debug.Log("03. ๋ฐฉ ์ƒ์„ฑ ์™„๋ฃŒ");
ย  ย  }

ย  ย  public override void OnJoinedRoom()
ย  ย  {
ย  ย  ย  ย  Debug.Log("04.๋ฐฉ ์ž…์žฅ ์™„๋ฃŒ");
ย  ย  ย  ย  if (PhotonNetwork.IsMasterClient)
ย  ย  ย  ย  ย  ย  GameManager.instance.isConnect = true;
ย  ย  }

}



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;

public class GameManager : MonoBehaviour
{
ย  public static GameManager instance=null;
ย  public bool isConnect=false;
ย  public ย Transform[] spawnPoints;

ย  private void Awake()
ย  {
ย  ย  if(instance==null)
ย  ย  {
ย  ย  ย  ย  instance=this;
ย  ย  ย  ย  DontDestroyOnLoad(this.gameObject);
ย  ย  }
ย  ย  else if (instance!= this)
ย  ย  {
ย  ย  ย  ย  Destroy(this.gameObject);
ย  ย  }

ย  }
ย  ย  void Start()
ย  ย  {
ย  ย  ย  ย  StartCoroutine(CreatePlayer());
ย  ย  ย  ย 
ย  ย  }

ย  ย  // Update is called once per frame
ย  ย  void Update()
ย  ย  {
ย  ย  ย  ย 
ย  ย  }
ย  ย  IEnumerator CreatePlayer(){
ย  ย  ย 
ย  ย  ย yield return new WaitUntil(() => isConnect);
ย  ย  ย  ย 
ย  ย  ย  ย  ย  ย  spawnPoints = GameObject.Find("SpawnPointGroup").GetComponentsInChildren<Transform>();
ย  ย  ย  ย  ย  ย  Vector3 posit = spawnPoints[PhotonNetwork.CurrentRoom.PlayerCount].position;
ย  ย  ย  ย  ย  ย 
ย  ย  ย  ย  ย  ย  GameObject playerTemp = PhotonNetwork.Instantiate("Player", posit,Quaternion.identity, 0);
ย  ย  ย  ย  ย  ย  Debug.Log("์บ๋ฆญํ„ฐ ์Šคํฐ๋จ");
ย  ย  ย  ย  }
ย  ย  }